关于WebServices的调用
阅读原文时间:2023年07月10日阅读:1

1.使用soapui测试接口是否能通    具体操作步骤请查看:https://www.cnblogs.com/BINDAI/p/13201513.html

Soapui请求结果集

2.获得soapui的地址栏的接口访问地址

地址栏获得的接口地址

http://192.168.1.103/wstopprd/ws/r/awsp900?Wsdl

访问接口地址为http://192.168.1.103/wstopprd/ws/r/awsp900

3.获得头部的SOAPAction

查看方法:

下面附上请求代码:

string URL = "http://192.168.1.103/wstopprd/ws/r/awsp900";
//创建请求
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL);
//创建头部信息
request.Method = "POST";
request.ContentType = "text/xml; charset=utf-8";
//具体请求查看soapui中的头部信息
request.Headers.Add("SOAPAction", "");这个为必填

//具体报文格式询问创建接口的开发
StringBuilder sb = new StringBuilder();
sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append(""); sb.Append("<request type=\"sync\" key=\"76CFB4D975B57C166A5F93C79E19D933\">"); sb.Append(" <host prod=\"CMS\" ver=\"1.0\" ip=\"192.168.1.103\" lang=\"zh_CN\" timezone=\"8\" timestamp=\"20200509085642517\" acct=\"tiptop\" />"); sb.Append("<service prod=\"T100\" name=\"cms.return1\" srvver=\"1.0\" id=\"00000\" />"); sb.Append("<datakey type=\"FOM\">"); sb.Append("<key name=\"EntId\">88</key>"); sb.Append("<key name=\"CompanyId\">WDK</key>"); sb.Append("</datakey>"); sb.Append("<payload>"); sb.Append(" <param key=\"data\" type=\"XML\">"); sb.Append("<![CDATA[ "); sb.Append(" <Request>"); sb.Append(" <RequestContent> "); sb.Append("<Parameter/>"); sb.Append(" <Document>"); sb.Append(" <RecordSet id=\"1\">"); if (model.D_PO_NO!=null&&model.D_PO_NO!="") { sb.Append("<Master name=\"l_xmdc\" node_id=\"1\"> "); sb.Append(" <Record> "); sb.Append(" <Field name=\"xmda033\" value=\"" + model.D_PO_NO + "\"/> "); sb.Append("<Field name=\"xmdcseq\" value=\"\"/>"); sb.Append("</Record> "); sb.Append(" </Master> "); } sb.Append(" </RecordSet>"); sb.Append("</Document> "); sb.Append(" </RequestContent> "); sb.Append(" </Request>]]>"); sb.Append("</param>"); sb.Append("</payload>"); sb.Append("</request>"); sb.Append(" "); sb.Append(" "); sb.Append(" "); sb.Append(" ");

//Sb为请求报文
//转为字节数组
byte[] data = System.Text.Encoding.ASCII.GetBytes(sb.ToString());
//获得字节长度
request.ContentLength = data.Length;

//开始请求
Stream writer = request.GetRequestStream();
writer.Write(data, , data.Length);
writer.Close();

// 回执信息
//using (var response = request.GetResponse())
using (WebResponse response = request.GetResponse()){

XmlDocument doc = new XmlDocument();
StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
//读取回执信息
string retXml = sr.ReadToEnd();
sr.Close();
//解析XML找到对应节点
doc.LoadXml(retXml);
var xmlStr = doc.SelectSingleNode("//response").ChildNodes[].InnerText;

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器