• c#(POST)动态对接SAP WebService接口


    1、通过软件工具SoapUI获取请求体和响应体

    第二步c#调用

     1  public XmlDocument QueryPostWebService(String URL, String MethodName, string inputPars, string userName, string passWord, string domain)
     2         {
     3             HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(URL);
     4             request.Method = "POST";
     5             request.ContentType = "text/xml; charset=utf-8";
     6             request.Headers.Add("Accept-Language", "zh;");//设置SAP登录语言为中文
     7             SetWebRequest(request, userName, passWord, domain);
     8             byte[] data = Encoding.UTF8.GetBytes(inputPars);
     9             WriteRequestData(request, data);
    10             return ReadXmlResponse(request.GetResponse());
    11         }
    12 
    13         private void SetWebRequest(HttpWebRequest request, string userName, string passWord, string domain = "saps4demo.sz-sunway.com")
    14         {
    15             NetworkCredential cred = new NetworkCredential(userName, passWord);
    16             request.Credentials = cred;
    17             request.Timeout = 120000;
    18         }
    19 
    20         private void WriteRequestData(HttpWebRequest request, byte[] data)
    21         {
    22             request.ContentLength = data.Length;
    23             Stream writer = request.GetRequestStream();
    24             writer.Write(data, 0, data.Length);
    25             writer.Close();
    26         }
    27 
    28         private XmlDocument ReadXmlResponse(WebResponse response)
    29         {
    30             StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
    31             String retXml = sr.ReadToEnd();
    32             sr.Close();
    33             XmlDocument doc = new XmlDocument();
    34             doc.LoadXml(retXml);
    35             return doc;
    36         }

    注意:

    SOAP V 1.1 --->参数使用:“soapenv:” 命名空间“http://schemas.xmlsoap.org/soap/envelope/”  request.ContentType="text/xml; charset=utf-8"

    SOAP V 1.2 --->参数使用:“soap:” 命名空间“http://www.w3.org/2003/05/soap-envelope”     request.ContentType="application/soap+xml; charset=utf-8"

  • 相关阅读:
    【美菜网】PostgreSQL与MySQL比较
    MySQL数据库MyISAM和InnoDB存储引擎的比较
    【美菜网】in和exist区别
    【美菜网】on、where以及having的区别
    hive 行列转换
    postgresql 发生锁表时的解锁操作
    postgre 中获取某个字段最小的另一个字段的记录
    关于带分区hive表添加字段如何避免插入的新字段数据为null
    git使用入门
    怎么绕过前端的判断提交
  • 原文地址:https://www.cnblogs.com/weifeng123/p/14812866.html
Copyright © 2020-2023  润新知