WebService 不用添加引用的方法

一、用   wsdl   /n:MyWeb   http://xxx.com/web/web1.asmx 生成一个web1.cs代理类文件  
   
  二、把web1.cs添加到web程序项目中,打开并修改它,  
  在它的类,修改它实例化的类成下面这种样子  
  public   class   web1   :   System.Web.Services.Protocols.SoapHttpClientProtocol   {  
                   
                  ///   <remarks/>  
                  public   web1(string   url)   {  
                          this.Url   =   url;//原来是一个http://xxx.com/web1/web1.asmx,现改成参数形式  
                  }  
   
  三、改一个asp.net项目的Web.config文件  
  在<configuration>一节中添加  
  <add   key="WebServiceUrl"   value="http://yyy.com/web/web.asmx"   />  
   
  四、在asp.net程序中调用Web服务  
  string   strUrl   =    
  System.Configuration.ConfigurationSettings.AppSettings["WebServiceUrl"].ToString();  
   
  MyWeb.web1   web   =   new   MyWeb.web1(strUrl);//实例化时动态调用一个Web   Service  
  string   strResult   =   web.Hello("world");   
   
原文地址:https://www.cnblogs.com/ggbbeyou/p/1640948.html