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;就可以请求成功了
3.使用C#代码进行调用
publicstaticvoidRequestSAP(string url,int timeout,string xmlData,string userName,string password,outstring statusCode,outstring resultContent){
statusCode ="400";
resultContent ="";try{byte[] bytes = Encoding.UTF8.GetBytes(xmlData);//Basic Authbyte[] 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()asHttpWebResponse;
statusCode = response.StatusCode.ToString("d");Stream responseStream = response.GetResponseStream();StreamReader sr =newStreamReader(responseStream, Encoding.UTF8);
resultContent = sr.ReadToEnd();
sr.Dispose();
requestStream.Close();
responseStream.Close();
response.Dispose();}catch(Exception ex){
statusCode ="400";
resultContent = ex.Message;}}
版权归原作者 M鹿M 所有, 如有侵权,请联系我们删除。