wns9778.com_威尼斯wns.9778官网

热门关键词: wns9778.com,威尼斯wns.9778官网
wns9778.com > 计算机教程 > C# Soap调WebService

原标题:C# Soap调WebService

浏览次数:159 时间:2019-05-10

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;
        }
    }

 

本文由wns9778.com发布于计算机教程,转载请注明出处:C# Soap调WebService

关键词: wns9778.com

上一篇:Node.js学习笔记 -- Node.js路由

下一篇:没有了