首页 / C# / c#对接SAP WebService接口
c#对接SAP WebService接口
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c#对接SAP WebService接口,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1999字,纯文字阅读大概需要3分钟。
内容图文
1、通过软件工具SoapUI获取请求体和响应体
第二步c#调用
1 private static HttpWebRequest CreateWebRequest() 2 { 3 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create 4 (@"http://XXX.XXX.com:8000/sap/bc/srt/rfc/sap/ztest_mes_01/300/ztest_mes_01/ztest_mes_01"); 5 webRequest.Headers.Add(@"SOAP:Action"); 6 webRequest.ContentType = "text/xml;charset=\"utf-8\""; 7 webRequest.Accept = "text/xml"; 8 webRequest.Method = "POST"; 9string authorization = "<code>UserName</code>" + 10":" + "<code>Pw</code>"; 11byte[] binaryAuthorization = System.Text.Encoding.UTF8.GetBytes(authorization); 12 authorization = Convert.ToBase64String(binaryAuthorization); 13 authorization = "Basic " + authorization; 14 webRequest.Headers.Add("AUTHORIZATION", authorization); 15return webRequest; 16 }
1 HttpWebRequest request = CreateWebRequest(); 2 XmlDocument soapEnvelopeXml = new XmlDocument(); 3 soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" 4encoding=""utf-8""?><soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:urn=""urn:sap-com:document:sap:soap:functions:mc-style""> 5 <soapenv:Header/> 6 <soapenv:Body> 7 <urn:ZtestMes01/> 8 </soapenv:Body> 9</soapenv:Envelope> "); 1011using (Stream stream = request.GetRequestStream()) 12 { 13 soapEnvelopeXml.Save(stream); 14 } 15try16 { 17using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) 18 { 19using (StreamReader rd = new StreamReader(response.GetResponseStream())) 20 { 21string soapResult = rd.ReadToEnd(); 22 } 23 } 24 } 25catch (Exception e) 26 { 27if (e is WebException && ((WebException)e).Status == WebExceptionStatus.ProtocolError) 28 { 29 WebResponse errResp = ((WebException)e).Response; 30using (Stream respStream = errResp.GetResponseStream()) 31 { 32using (StreamReader rd = new StreamReader(respStream)) 33 { 34string soapResult = rd.ReadToEnd(); 35 } 36 } 37 } 38 }
原文:https://www.cnblogs.com/weifeng123/p/14812866.html
内容总结
以上是互联网集市为您收集整理的c#对接SAP WebService接口全部内容,希望文章能够帮你解决c#对接SAP WebService接口所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。