I am trying to create a web service consumer, given a WSDL of a service that is already up and running. The challenge is, doing the whole thing dynamically, in runtime. I am working with C#. To sum up, I have to do the following:
- I have an application that will be given as input the WSDL file (url). done
- The application will drill down the WSDL file, recognizing the operations, messages and the types used. (point that I'm having trouble with)
- It will create the code needed to invoke the Web Service, compile it and load it through reflection. done
- Have everything ready for invocation, including creating and sending the necessary parameters to the remote method. Then it'll handle the response properly. done
I am having some issues with #2, which is parsing and drilling down in the WSDL file. In specific: extracting complex types that appear to be "nested".
I've read some very useful resources about extracting complex types:
Parse Complex WSDL Parameter Information
Detailed ServiceDescription / Proxy from WSDL
http://mikehadlow.blogspot.com/2006/06/simple-wsdl-object.html
However, I am a bit puzzled with an example WSDL that I have received for testing:
<definitions name='MyWSService' targetNamespace='http://some.url.com/' xmlns='http://schemas.xmlsoap.org/wsdl/' xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' xmlns:tns='http://some.url.com/' xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
<types>
<xs:schema attributeFormDefault='qualified' elementFormDefault='qualified' targetNamespace='http://some.url.com/' version='1.0' xmlns:tns='http://some.url.com/' xmlns:xs='http://www.w3.org/2001/XMLSchema'>
<xs:element name='dsSendOperationName' type='tns:systemSendOperationName'/>
<xs:element name='dsSendOperationNameResponse' type='tns:systemSendOperationNameResponse'/>
<xs:complexType name='systemSendOperationName'>
<xs:sequence>
<xs:element minOccurs='0' name='systemOperationName' type='tns:systemOperationName'/>
</xs:sequence>
</xs:complexType>
<xs:complexType name='systemOperationName'>
<xs:sequence>
<xs:element minOccurs='0' name='param1' type='xs:string'/>
<xs:element minOccurs='0' name='param2' type='xs:string'/>
<xs:element minOccurs='0' name='param3' type='xs:string'/>
<xs:element minOccurs='0' name='param4' type='xs:string'/>
<xs:element minOccurs='0' name='param5' type='xs:string'/>
</xs:sequence>
</xs:complexType>
<xs:complexType name='systemSendOperationNameResponse'>
<xs:sequence>
<xs:element minOccurs='0' name='return' type='xs:string'/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</types>
<message name='SystemOperationNameWS_dsSendOperationName'>
<part element='tns:dsSendOperationName' name='dsSendOperationName'></part>
</message>
<message name='SystemOperationNameWS_dsSendOperationNameResponse'>
<part element='tns:dsSendOperationNameResponse' name='dsSendOperationNameResponse'></part>
</message>
<portType name='SystemOperationNameWS'>
<operation name='dsSendOperationName' parameterOrder='dsSendOperationName'>
<input message='tns:SystemOperationNameWS_dsSendOperationName'></input>
<output message='tns:SystemOperationNameWS_dsSendOperationNameResponse'></output>
</operation>
</portType>
<binding name='SystemOperationNameWSBinding' type='tns:SystemOperationNameWS'>
<soap:binding style='document' transport='http://schemas.xmlsoap.org/soap/http'/>
<operation name='dsSendOperationName'>
<soap:operation soapAction=''/>
<input>
<soap:body use='literal'/>
</input>
<output>
<soap:body use='literal'/>
</output>
</operation>
</binding>
<service name='SystemOperationNameWSService'>
<port binding='tns:SystemOperationNameWSBinding' name='SystemOperationNameWSPort'>
<soap:address location='http://a.url.here.com'/>
</port>
</service>
</definitions>
Look how the root elements (as defined in the messages' section) are referring to a complex type, which has an element that is later on declared as a complex type, that finally has a sequence of elements with standard XSD types.
Programatically, I am able to drill down to the very last element of that "chain". However, I am confused about the type of the actual message being sent to the web service. Is it:
- A systemSendOperationName that wraps a systemOperationName, that contains 5 strings? or
- A systemOperationName object that contains 5 strings?
And overall, is that sort of nested types normal? I haven't found a similar example so far.
EDIT:
Made some points of my initial post more clear to avoid any confusions.