zoukankan      html  css  js  c++  java
  • 关于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;

     

  • 相关阅读:
    opencv下载,安装教程
    VS2010中程序编译生成都是正确的,直接生成的exe也是正确的,就是在VS中运行出现错误
    Oracle11g em启动报此网站的安全证书有问题的解决方案
    Python教程百度云资源分享,全套,完整版!!!
    Python视频教程免费分享(2020年最新版)
    Python 环境搭建(Win 安装以及Mac OS 安装)
    Python学习路线图(2020年最新版)
    Python爬虫入门教程之BeautifulSoup
    Python数据分析练手:分析知乎大V
    python 可变对象与不可变对象
  • 原文地址:https://www.cnblogs.com/BINDAI/p/13201643.html
Copyright © 2011-2022 走看看