本文原文链接:http://www.cnblogs.com/dengxinglin/p/3334158.html html
以前一篇文章写 Web Service服务代理类生成及编译 , 经过命令行的方式能够直接把SOAP的Webservice服务生成代理类,再编译成一个dll工具
需求post
既然上面能够生成了代理类,而且若是我有几个WebService须要生成,或者屡次要生成代理类编译dll的,这样就会很麻烦了。把这生成代理类和编译成dll的作成一个工具就会带来方便。ui
开始行动url
先直接上效果图片spa
第一步:命令行
把须要到的两个工具:wsdl.exe和csc.exe工具给单独复制出来代理
第二步:调试
经过C#来代码来执行那两个命令行工具下面是个人一个方法:code
/// <summary> /// 输入参数执行命令的方法 /// </summary> /// <param name="argument"></param> /// <returns></returns> public string Startcmd(string argument) { string output = ""; try { Process cmd = new Process(); cmd.StartInfo.FileName = FileName; cmd.StartInfo.Arguments = argument; cmd.StartInfo.UseShellExecute = false; cmd.StartInfo.RedirectStandardInput = true; cmd.StartInfo.RedirectStandardOutput = true; cmd.StartInfo.CreateNoWindow = true; cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; cmd.Start(); output = cmd.StandardOutput.ReadToEnd(); //Console.WriteLine(output); cmd.WaitForExit(); cmd.Close(); } catch (Exception e) { output = e.ToString(); return output; // Console.WriteLine(e); } return output; }
第三步:
调试。在wsdl工具生成代理通常都没有问题,也能正常生成代理类;可是用csc编译成dll的时候,运行csc工具会有错误,咱们须要引用一个cscompui.dll,安装vs后能够直接找到的。还须要把代理中引用的程序集都填写上,也包括是系统的程序集。通常会包括下面的命名空间引用
using System.Xml.Serialization; using System.Web.Services; using System.ComponentModel; using System.Web.Services.Protocols; using System; using System.Diagnostics; using System.Data;
System.Xml.Serialization 是在System.XML.dll程序集
System.Web.Services 程序集是System.Web.Services.dll
using System.Diagnostics;using System.ComponentModel;using System;程序集都在System.dll
System.Data的程序集是System.Data.dll
我把那四个程序集的framework3.5的单独复制出来的;
你若是是要修改为4.0:
一:能够本身找到4.0下面相应的dll去替换掉,
二:先把这个项目修改为framework4.0的项目,以后在程序中References-->System.Data--》properties-->Copy local的属性值给为true,就到复制出framework4.0的版本dll,
若是csc编译有错误:根据返回的错误代码能够参考http://msdn.microsoft.com/zh-cn/library/ms228296.aspx,均可以找到缘由的。
上传速度太慢,在博客园上传不了,上传到了百度网盘:百度网盘下载
备注: 因为wsdl生成的代理类和方法大都是公共的,若是两个不一样的WebService,生成使用了相同的命名空间,则在csc编译的时候会有错误,这只能去手动解决或者那两个生成的代码放在不一样的命名空间了。