首页 > Web开发 > 详细

.Net webservice动态调用

时间:2014-06-28 13:09:42      阅读:394      评论:0      收藏:0      [点我收藏+]

直接贴代码吧

public class PmsService
   {
       /// <summary>
       /// pms接口
       /// </summary>
       /// <param name="invokeBaseData">接口传递数据类</param>
       /// <returns> </returns>
       public string InvokeService(InvokeBaseData invokeBaseData)
       {
           string result = "", tempUrl = "", content = "";
           tempUrl = "http://115.238.104.156:5031/XRself/HepInterface_Service.asmx/WebConnector";
           content = "v=" + invokeBaseData.Version + "&n=" + invokeBaseData.Number +
               "&f=" + invokeBaseData.Function + "&q=" + invokeBaseData.QueryString + 
               "&c=" + invokeBaseData.ClientInfo + "&s=" + invokeBaseData.State;
           StreamReader myStreamReader;
           var bs = Encoding.UTF8.GetBytes(content);
           var request = (HttpWebRequest)HttpWebRequest.Create(tempUrl);
           request.Method = "POST";
           request.ContentType = "application/x-www-form-urlencoded";
           request.ContentLength = bs.Length;
           try
           {
               using (Stream reqStream = request.GetRequestStream())
               {
                   reqStream.Write(bs, 0, bs.Length);
                   reqStream.Close();
               }
               var wr = request.GetResponse();
               var myResponseStream = wr.GetResponseStream();
               myStreamReader = new StreamReader(myResponseStream);
               result = myStreamReader.ReadToEnd();
           }
           catch (WebException ce)
           {
               var res = (HttpWebResponse)ce.Response;
               try
               {
                   myStreamReader = new StreamReader(res.GetResponseStream());
                   result = myStreamReader.ReadToEnd();
               }
               catch (Exception e)
               {
                   result = ce.Message;
               }
           }
           return result;
       }
   }

想交流qq联系:1576410833

.Net webservice动态调用,布布扣,bubuko.com

.Net webservice动态调用

原文:http://www.cnblogs.com/zhangwei595806165/p/3798671.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!