通过WSDL 命令,实现远程调用webservice
远程调用webservice 的方法:
通过wsdl命令,生成webservice 对应asmx 文件的对应类(cs文件),然后将此cs文件引用到当前项目中,项目其他地方需要调用webservice方法,可以直接调用cs类中的对应方法就可以实现对远程webservice 的调用。
具体步骤:
1.wsdl 生成指定地址的cs文件,步骤如下:
开始--》programes--》vs2008--》tools--》vs2008 command prompt 打开命令行窗口
wsdl /l:cs /n:newNamespace /out:myServiceName.cs http://ip/path/serviceName.asmx
之后copy myServiceName.cs文件到 项目的一个文件夹中。修改namespace 与当前项目名称一致, 以使得能够顺利调用,
2. 在 myServiceName.cs文件中 有个public myServiceName(){...}中 设置 asmx的 url 地址为你想要的url 地址
例如:http://www.sina.com.cn/serviceName.asmx
或者修改 public myservice(string strUrl){this.url=strUrl;}
在实例化 myservice 的实例时, 可以输入此url 地址.
或者从配置文件中读取
public myservice(){
this.Url =System.Configuration.ConfigurationManager.AppSettings["settingName"];
}
浙公网安备 33010602011771号