go语言简单的soap调用方法
package main import (
"bytes"
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"net/http"
"strings"
) // The URL of the SOAP server
const MH_SOAP_URL = "http://sp.mountyhall.com/SP_WebService.php" // this is just the message I'll send for interrogation, with placeholders
// for my parameters
const SOAP_VUE_QUERY_FORMAT = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:tns=\"urn:SP_WebService\" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" ><SOAP-ENV:Body><mns:Vue xmlns:mns=\"uri:mhSp\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><numero xsi:type=\"xsd:string\">%d</numero><mdp xsi:type=\"xsd:string\">%s</mdp></mns:Vue></SOAP-ENV:Body></SOAP-ENV:Envelope>" // Here I define Go structures, almost identical to the structure of the
// XML message we'll fetch
// Note that annotations (the string "return>item") allow to have a slightly
// different structure or different namings type SoapItem struct {
Numero int
Nom string
Type string
PositionX int
PositionY int
PositionN int
Monde int
}
type SoapVue struct {
Items []SoapItem "return>item"
}
type SoapFault struct {
Faultstring string
Detail string
}
type SoapBody struct {
Fault SoapFault
ProfilResponse SoapProfil
VueResponse SoapVue
}
type SoapEnvelope struct {
XMLName xml.Name
Body SoapBody
} // Here is the function querying the SOAP server
// It returns the whole answer as a Go structure (a SoapEnvelope)
// You could also return an error in a second returned parameter
func GetSoapEnvelope(query string, numero int, mdp string) (envelope *SoapEnvelope) {
soapRequestContent := fmt.Sprintf(query, numero, mdp)
httpClient := new(http.Client)
resp, err := httpClient.Post(MH_SOAP_URL, "text/xml; charset=utf-8", bytes.NewBufferString(soapRequestContent))
if err != nil {
// handle error
}
b, e := ioutil.ReadAll(resp.Body) // probably not efficient, done because the stream isn't always a pure XML stream and I have to fix things (not shown here)
if e != nil {
// handle error
}
in := string(b)
parser := xml.NewDecoder(bytes.NewBufferString(in))
envelope = new(SoapEnvelope) // this allocates the structure in which we'll decode the XML
err = parser.DecodeElement(&envelope, nil)
if err != nil {
// handle error
}
resp.Body.Close()
return
}
go语言简单的soap调用方法的更多相关文章
- DLL简单分析与调用方法
最近为了分析一个没有代码的DLL有哪些函数,找了各种方法. 把结果分享一下:三个方法都没法得到函数的参数,有点让我失望. DLL Export Viewer NikPEViewer Dumpbin 配 ...
- onvif规范的实现:使用gSOAP创建SOAP调用实例
预备知识 ONVIF规范中设备管理和控制部分所定义的接口均以Web Services的形式提供.ONVIF规范涵盖了完全的XML及WSDL的定义.每一个支持ONVIF规范的终端设备均须提供与功能相应的 ...
- R语言:用简单的文本处理方法优化我们的读书体验
博客总目录:http://www.cnblogs.com/weibaar/p/4507801.html 前言 延续之前的用R语言读琅琊榜小说,继续讲一下利用R语言做一些简单的文本处理.分词的事情.其实 ...
- 简单实现RN调用原生方法(IOS)
在React Native中,一个“原生模块”就是一个实现了“RCTBridgeModule”协议的Objective-C类(个人理解RCTBridgeModule就是react与native之间的桥 ...
- 【Pyqt5】自定义信号简单原理(易懂版),多窗口交互,传输数据,调用方法
PS:如果你想在2窗口调用1窗口的内部方法,或者在2窗口传递数据给1窗口数据,本片博客可以放心食用 主窗口: class MainWindow(QWidget,Ui_MainFrom): insert ...
- WebService服务调用方法介绍
1 背景概述 由于在项目中需要多次调用webservice服务,本文主要总结了一下java调用WebService常见的6种方式,即:四种框架的五种调用方法以及使用AEAI ESB进行调用的方法. 2 ...
- PHP5下SOAP调用实现过程
本文以某公司iPhone 6手机预约接口开发为例,介绍PHP5下SOAP调用的实现过程. 一.基础概念 SOAP(Simple Object Access Protocol )简单对象访问协议是在分散 ...
- PHP5下WSDL,SOAP调用实现过程
一.基础概念 SOAP(Simple Object Access Protocol )简单对象访问协议是在分散或分布式的环境中交换信息的简单的协议,是一个基于XML的协议,它包括四个部分:SOAP封装 ...
- PHP使用SOAP调用.net的WebService数据
需要和一个.net系统进行数据交换,对方提供了一个WebService接口,使用PHP如何调用这个数据呢,下面就看看使用SOAP调用的方法吧 这个与一般的PHP POST或GET传值再查库拿数据的思路 ...
随机推荐
- 如何得到WPF中控件绑定的EventTrigger
System.Windows.Interactivity.Interaction.GetTriggers(sender as DependencyObject)[0].Actions
- jquery/原生js/css3 实现瀑布流以及下拉底部加载
思路: style: <style type="text/css"> body,html{ margin:; padding:; } #container{ posit ...
- linux下如何使用Mysql
项目需要:Linux下链接数据库,并进行相关的查询操作 mySql的一些常用命令 启动:net start mySql; 进入:mysql -u root -p/mysql -h localhost ...
- iView之DatePicker的datetimerange校验
使用DatePicker的type是datetimerange时,处理开始--结束的持续时间校验如下.遇到的问题:时间弹出校验提示,但是程序还是会继续往下走,所以调完校验后,再做判断开始时间是否为tr ...
- asp.net mvc cookie超时返回登录页面问题
filterContext.HttpContext.Response.Write("<script>top.location.href = '/Login/Index';< ...
- Auto Layout Guide----(一)-----Understanding Auto Layout
Understanding Auto Layout 理解自动布局 Auto Layout dynamically calculates the size and position of all the ...
- WCF大文件传输【转】
http://www.cnblogs.com/happygx/archive/2013/10/29/3393973.html WCF大文件传输 WCF传输文件的时候可以设置每次文件的传输大小,如果是小 ...
- LeetCode: 492 Construct the Rectangle(easy)
题目: or a web developer, it is very important to know how to design a web page's size. So, given a sp ...
- 洛谷P2217 [HAOI2007]分割矩阵
P2217 [HAOI2007]分割矩阵 题目描述 将一个a*b的数字矩阵进行如下分割:将原矩阵沿某一条直线分割成两个矩阵,再将生成的两个矩阵继续如此分割(当然也可以只分割其中的一个),这样分割了(n ...
- 详解环境搭建SSM
1.概述: SSM即为spring 4 +spring mvc +mybatis 3.4.6 推荐使用maven或者gradle 来配置 下面给出maven配置方式 2.项目结构: 新建web项目 这 ...