2011-11-01 197 views
4

使用microsoft net wsdl.exe工具將WSDL轉換爲C#類,但該工具無法轉換WSDL文件的以下部分。任何指針在正確的方向非常讚賞。將WSDL轉換爲C#類

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 
{ 
} 

我想知道如何定義類「商人」和「ArrayOfMerchant」。

謝謝。

+4

什麼是您所遇到的具體問題?另外,您是否知道WSDL.EXE是傳統技術?你應該使用svcutil.exe或者只是使用「添加服務引用」,除非你被困在.NET 2.0中。 –

+1

我正在採取不同的方法,使用以下URL作爲起點http://stackoverflow.com/questions/4791794/c-sharp-client-send-soap-request-and-get-results。不知道關閉這個問題的最佳方式。 – Steven

回答

21

如果你和你一起獲得了WSDL,那麼它是staright forward來創建C#代理類。

下面提到的是其中的一種方法。如果您的WSDL數據未通過URL公開。 首先可用的WSDL數據保存到一個文件中說: 「d:\ MerchantService.wsdl」

svcutil.exe D:\MerchantService.wsdl /t:code /l:c# /o:"D:\MerchantService.cs" /n:*,NamespaceName 

Refrence:在XSD http://msdn.microsoft.com/en-us/library/aa347733.aspx

+1

C#輸出顯示由wsdl.exe生成,但對於不生成任何內容。因此,我無法通過arrMerchant [0] .iId訪問服務返回的數據。 – Steven

+0

@Steven您是否嘗試過使用svcutil.exe並查看您的複雜類型是否已生成? –

+1

svcutil.exe不幸的產生了相同的問題。進一步研究了一些事情後,我發現正在使用的WSDL已知會導致.NET出現問題,因此我採用了以下URL作爲起點的不同方法http://stackoverflow.com/questions/4791794/c-銳利的客戶端發送皁請求和-GET-結果。不知道關閉這個問題的最佳方式。 – Steven