关于WebServices的调用

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("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tip=\"http://www.digiwin.com.cn/tiptop/TIPTOPServiceGateWay\">");
                sb.Append("<soapenv:Header/>");
                sb.Append("<soapenv:Body>");
                sb.Append("<tip:invokeSrv>");
                sb.Append("<request>");
                sb.Append("&lt;request type=\"sync\" key=\"76CFB4D975B57C166A5F93C79E19D933\"&gt;");
                sb.Append(" &lt;host prod=\"CMS\" ver=\"1.0\" ip=\"192.168.1.103\" lang=\"zh_CN\" timezone=\"8\" timestamp=\"20200509085642517\" acct=\"tiptop\" /&gt;");
                sb.Append("&lt;service prod=\"T100\" name=\"cms.return1\" srvver=\"1.0\" id=\"00000\" /&gt;");
                sb.Append("&lt;datakey type=\"FOM\"&gt;");
                sb.Append("&lt;key name=\"EntId\"&gt;88&lt;/key&gt;");
                sb.Append("&lt;key name=\"CompanyId\"&gt;WDK&lt;/key&gt;");
                sb.Append("&lt;/datakey&gt;");
                sb.Append("&lt;payload&gt;");
                sb.Append("  &lt;param key=\"data\" type=\"XML\"&gt;");
                sb.Append("&lt;![CDATA[  ");
                sb.Append(" &lt;Request&gt;");
                sb.Append(" &lt;RequestContent&gt; ");
                sb.Append("&lt;Parameter/&gt;");
                sb.Append("  &lt;Document&gt;");
                sb.Append("  &lt;RecordSet id=\"1\"&gt;");
                if (model.D_PO_NO!=null&&model.D_PO_NO!="")
                {
                    sb.Append("&lt;Master name=\"l_xmdc\" node_id=\"1\"&gt;  ");
                    sb.Append(" &lt;Record&gt;  ");
                    sb.Append(" &lt;Field name=\"xmda033\" value=\"" + model.D_PO_NO + "\"/&gt; ");
                    sb.Append("&lt;Field name=\"xmdcseq\" value=\"\"/&gt;");
                    sb.Append("&lt;/Record&gt; ");
                    sb.Append(" &lt;/Master&gt; ");
                }
                sb.Append(" &lt;/RecordSet&gt;");
                sb.Append("&lt;/Document&gt; ");
                sb.Append(" &lt;/RequestContent&gt; ");
                sb.Append(" &lt;/Request&gt;]]&gt;");
                sb.Append("&lt;/param&gt;");
                sb.Append("&lt;/payload&gt;");
                sb.Append("&lt;/request&gt;");
                sb.Append(" </request>");
                sb.Append("  </tip:invokeSrv>");
                sb.Append(" </soapenv:Body>");
                sb.Append(" </soapenv:Envelope>");
//Sb为请求报文
//转为字节数组
byte[] data = System.Text.Encoding.ASCII.GetBytes(sb.ToString());
//获得字节长度
                request.ContentLength = data.Length;
                
//开始请求
Stream writer = request.GetRequestStream();
 writer.Write(data, 0, 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[0].InnerText;

 

 

 

 

 

 

 

 

 

 

 

 

 

posted on 2020-06-28 10:34  BIN_Coisini  阅读(226)  评论(0编辑  收藏  举报

导航