1.使用SoapUI 解析wsdl
SAP wsdl地址发放在浏览器中是需要输入用户名密码进行认证的
将wsdl地址放到SoapUI进行解析
输入用户名密码
左边就是请求的XML格式,右边是接口返回内容,点击运行就可以看到结果
2.使用Postman调用
Request1的地址就是我们需要调用的地址(这里提供的域名和wsdl 的域名不一致,需要换成wsdl的域名,SAP是用了跳转网址的),将soapui左边的XML复制到postman中,接口需要在header中加入SOAPAction,SOAPAction在soapui工具的Raw中,如图:
Content-Type : text/xml;charset=UTF-8;
Headers中一定要加入SOAPAction;
Body中选择Raw Xml进行请求
再加上认证Basic Auth;就可以请求成功了文章来源:https://www.toymoban.com/news/detail-709067.html
文章来源地址https://www.toymoban.com/news/detail-709067.html
3.使用C#代码进行调用
public static void RequestSAP(string url, int timeout, string xmlData, string userName, string password, out string statusCode, out string resultContent)
{
statusCode = "400";
resultContent = "";
try
{
byte[] bytes = Encoding.UTF8.GetBytes(xmlData);
//Basic Auth
byte[] byteUser = Encoding.Default.GetBytes(userName + ":" + password);
string Authorization = Convert.ToBase64String(byteUser);
HttpWebRequest request = HttpWebRequest.CreateHttp(url);
//避免远程连接证书无效问题
ServicePointManager.ServerCertificateValidationCallback = (s, certificate, chain, errs) => true;
request.Method = "POST";
request.Timeout = timeout;
request.ContentType = "text/xml;charset=UTF-8";
request.ContentLength = bytes.Length;
request.Headers.Add("Authorization", "Basic " + Authorization);
//根据soapui中的SOAPAction 进行赋值
request.Headers.Add("SOAPAction", "SOAPAction");
Stream requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
statusCode = response.StatusCode.ToString("d");
Stream responseStream = response.GetResponseStream();
StreamReader sr = new StreamReader(responseStream, Encoding.UTF8);
resultContent = sr.ReadToEnd();
sr.Dispose();
requestStream.Close();
responseStream.Close();
response.Dispose();
}
catch (Exception ex)
{
statusCode = "400";
resultContent = ex.Message;
}
}
到了这里,关于C# 调用SAP WebService接口(SoapUI Postman)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!