11

Converting WSDL to C# classes using microsoft net wsdl.exe tool but the tool is unable to convert the following part of the WSDL file. Any pointers in the right direction greatly appreciated.

WSDL Input

<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# Output ?????

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

I would like to know how to define the class 'Merchant' and 'ArrayOfMerchant'.

Thanks.

Steven
  • 123
  • 1
  • 1
  • 5
  • 5
    What is the specific problem you're having? Also, are you aware that WSDL.EXE is legacy technology? You should use svcutil.exe or just use "Add Service reference", unless you're stuck with .NET 2.0. – John Saunders Nov 01 '11 at 23:06
  • 1
    I'm making headway taking a different approach using the following URL as a starting point http://stackoverflow.com/questions/4791794/c-sharp-client-send-soap-request-and-get-results. Not sure on the best way to close this question. – Steven Nov 02 '11 at 10:10

2 Answers2

39

If you got the WSDL with you it is straightforward to create the C# proxy class.

Below mentioned is one of the way to do it. If your WSDL data is not exposed via a URL. First save the Available WSDL data into a file say "D:\MerchantService.wsdl"

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

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

Luke Girvin
  • 12,672
  • 8
  • 57
  • 79
Vikram Shetty
  • 687
  • 6
  • 18
  • 1
    The C# output show is generated by wsdl.exe but nothing is generated for or . As a result I am unable to access the data returned from the service by, say, arrMerchant[0].iId. – Steven Nov 02 '11 at 08:22
  • @Steven Did you tried using svcutil.exe and see if your complex type is getting generated? – Vikram Shetty Nov 03 '11 at 07:19
  • 1
    svcutil.exe unfortunately yielded the same issues. Having looked into things further I discovered that the WSDL being used is known to cause issues with .NET so I've taken a different approach using the following URL as a starting point http://stackoverflow.com/questions/4791794/c-sharp-client-send-soap-request-and-get-results. Not sure on the best way to close this question. – Steven Nov 03 '11 at 16:19
5

Your problem relies in the XSD. svcutil doesn't support restrictions inside a complexContent tag: http://msdn.microsoft.com/en-us/library/ms733112.aspx

The msdn says it's actualy forbidden:

enter image description here

Mittchel
  • 1,784
  • 3
  • 16
  • 35