将WSDL转换为C#类

13

使用微软的net wsdl.exe工具将WSDL转换为C#类,但该工具无法转换WSDL文件的以下部分。非常感谢您提供正确方向的任何指针。

WSDL输入

<complexType name="Merchant">
 <sequence>
  <element name="iId" type="xsd:int" />
  <element name="sName" type="xsd:string" />
  <element name="sDescription" type="xsd:string" minOccurs="0" />
  <element name="aSectors" type="api:ArrayOfMerchantSectors" minOccurs="0" />
 </sequence>
</complexType>

<complexType name="ArrayOfMerchant">
 <complexContent>
  <restriction base="soapenc:Array">
   <attribute ref="soapenc:arrayType" wsdl:arrayType="api:Merchant[]" />
  </restriction>
 </complexContent>
</complexType>

<complexType name="MerchantSector">
 <sequence>
  <element name="iSectorId" type="xsd:int" />
  <element name="sSectorName" type="xsd:string" />
 </sequence>
</complexType>

<complexType name="ArrayOfMerchantSectors">
 <complexContent>
  <restriction base="soapenc:Array">
   <attribute ref="soapenc:arrayType" wsdl:arrayType="api:MerchantSector[]" />
  </restriction>
 </complexContent>
</complexType>

C#输出问题

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://api.someexampledomain.com/")]
public partial class ArrayOfMerchant : Array
{
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://api.someexampledomain.com/")]
public partial class ArrayOfMerchantSectors : Array
{
}

我想知道如何定义'Merchant'和'ArrayOfMerchant'这两个类。

谢谢。


5
你遇到了什么具体的问题?另外,你是否知道WSDL.EXE是遗留技术?除非你被困在.NET 2.0中,否则你应该使用svcutil.exe或者直接使用“添加服务引用”。 - John Saunders
1
我正在采用不同的方法取得进展,使用以下URL作为起点https://dev59.com/Bm445IYBdhLWcg3wkLTU。不确定关闭此问题的最佳方法。 - Steven
2个回答

43
如果您拥有WSDL文件,创建C#代理类就变得非常简单。
下面是一种方法。如果您的WSDL数据未通过URL公开,请先将可用的WSDL数据保存到文件中,例如“D:\MerchantService.wsdl”。
svcutil.exe D:\MerchantService.wsdl /t:code /l:c# /o:"D:\MerchantService.cs" /n:*,NamespaceName 

参考资料:http://msdn.microsoft.com/en-us/library/aa347733.aspx 抱歉,您没有提供需要翻译的内容。请提供需要翻译的内容以便我能够完成任务。

1
C#输出显示是由wsdl.exe生成的,但对于<complexType name="Merchant">或<complexType name="MerchantSector">没有生成任何内容。因此,我无法访问从服务返回的数据,例如arrMerchant [0] .iId。 - Steven
@Steven 你试过使用svcutil.exe来查看你的复杂类型是否被生成了吗? - Vikram Shetty
1
svcutil.exe不幸地产生了相同的问题。经过进一步的调查,我发现所使用的WSDL已知会在.NET中引起问题,因此我采用了不同的方法,以以下URL作为起点:https://dev59.com/Bm445IYBdhLWcg3wkLTU。不确定如何最好地关闭这个问题。 - Steven

5

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接