这里适用于已知wsdl文件地址,动态调用服务,即知道wsdl地址和方法名称便可调用其服务,下面代码是反射读取文件的过程。
public static void getWebservice(string nodeno)
{
//这里的namespace是需引用的webservices的命名空间,我没有改过,也可以使用。也可以加一个参数从外面传进来。
try
{
LogWrite.WriteLog("", "开始实例化wsdl", nodeno);
//获取WSDL
WebClient wc = new WebClient();
Stream stream = wc.OpenRead(url + "?WSDL");
ServiceDescription sd = ServiceDescription.Read(stream);
classname = sd.Services[0].Name;
ServiceDescriptionImporter sdi = new ServiceDescriptionImporter();
sdi.AddServiceDescription(sd, "", "");
CodeNamespace cn = new CodeNamespace(@namespace);
//生成客户端代理类代码
CodeCompileUnit ccu = new CodeCompileUnit();
ccu.Na