实例如下所示:
public class webservicehelper { /// <summary> /// soap协议post方法 /// </summary> /// <param name="uri">webservice地址</param> /// <param name="str">传入soap协议格式数据</param> /// <returns></returns> public static string sendtoreturn(uri _uri, string _str) { string _returnstr = ""; //发起请求 webrequest webrequest = webrequest.create(_uri); webrequest.contenttype = "text/xml; charset=utf-8"; webrequest.method = "post"; using (stream requeststream = webrequest.getrequeststream()) { byte[] parambytes = encoding.utf8.getbytes(_str); requeststream.write(parambytes, 0, parambytes.length); } //响应 try { webresponse webresponse = webrequest.getresponse(); using (streamreader mystreamreader = new streamreader(webresponse.getresponsestream(), encoding.utf8)) { _returnstr = mystreamreader.readtoend(); } } catch (webexception ex) { _returnstr = new streamreader(ex.response.getresponsestream()).readtoend(); } return _returnstr; } }
以上这篇c# soap调用webservice的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论