利用wsdl.exe自动将wsdl文档转换为C#代码

1.获取完整的wsdl文档

获取下面这个博客中提到的wsdl

 http://www.cnblogs.com/LCCRNblog/p/3716406.html

将获取到的wsdl放到一个文本中,改后缀(我放到mywsdl.wsdl),然后将wsdl文档放到桌面一个wsdl文件夹。

2.找到wsdl.exe

wsdl.exe一般在C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin中,找到它后在环境变量中添加这个路径。

3.使用wsdl.exe

打开cmd。

可以输入:wsdl /?,理解wsdl命令的参数;

接下来就是怎样获取C#代码的过程。

输入命令:wsdl.exe /si C:\Users\LC\Desktop\wsdl\mywsdl.wsdl /out:C:\Users\LC\Desktop\wsdl

/si 和 /out:(冒号不能少,我第一次做的时候就是少了冒号,就不成功)这两个参数的意思可以查看刚才wsdl的参数列表,

/si 后跟wsdl所在路径

/out: 后跟生成C#文件的存放路径

生成的文件名为ServiceInterfaces.cs

内容如下:

 1 //------------------------------------------------------------------------------
 2 // <auto-generated>
 3 //     此代码由工具生成。
 4 //     运行时版本:2.0.50727.5477
 5 //
 6 //     对此文件的更改可能会导致不正确的行为,并且如果
 7 //     重新生成代码,这些更改将会丢失。
 8 // </auto-generated>
 9 //------------------------------------------------------------------------------
10 
11 using System;
12 using System.ComponentModel;
13 using System.Diagnostics;
14 using System.Web.Services;
15 using System.Web.Services.Protocols;
16 using System.Xml.Serialization;
17 
18 // 
19 // 此源代码由 wsdl 自动生成, Version=2.0.50727.3038。
20 // 
21 
22 
23 /// <remarks/>
24 [System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
25 [System.Web.Services.WebServiceBindingAttribute(Name="ServiceSoap", Namespace="http://tempuri.org/")]
26 public interface IServiceSoap {
27     
28     /// <remarks/>
29     [System.Web.Services.WebMethodAttribute()]
30     [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/addition", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
31     double addition(double i, double j);
32     
33     /// <remarks/>
34     [System.Web.Services.WebMethodAttribute()]
35     [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/subtract", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
36     double subtract(double i, double j);
37     
38     /// <remarks/>
39     [System.Web.Services.WebMethodAttribute()]
40     [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/mutiplication", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
41     double mutiplication(double i, double j);
42     
43     /// <remarks/>
44     [System.Web.Services.WebMethodAttribute()]
45     [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/division", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
46     double division(double i, double j);
47 }

在此可以和之前那个博客中的代码进行比较一下,看看他们之间的区别。

转载于:https://www.cnblogs.com/LCCRNblog/p/3717702.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值