Reputation: 3673
I'm trying to consume this SOAP with a .NET Web Application using Visual Studio.
My question is, if my wsdl describes only two methods; 'processMessage
' and 'processOCIMessage
'. And the message they expect is a string that fits one of 30 something xsd schemas, what's the best way to consume the API?
For example, if I wanted to get some user information. I need to write a string that fits this schema:
<xs:complexType name="UserGetRequest19">
<xs:annotation>
<xs:documentation>
Request to get the user information. The response is either
UserGetResponse19 or ErrorResponse.
</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="core:OCIRequest">
<xs:sequence>
<xs:element name="userId" type="UserId"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
I know how to pass in simple parameters as described in the answer to this question. But how do I do that with Schemas?
Are there tools in Visual Studio that will turn these into user friendly C# classes/models? Or do I need to manually type out XML strings, escape the special characters and pass it in as parameter to 'processMessage
'?
Upvotes: 2
Views: 2702
Reputation: 21658
First, use the built-in tools to add a Visual Studio Web Reference starting from the WSDL. This should create your client side proxies, and the data transfer classes; you will eventually get a class with a property for processMessageReturn
as a string, and another class with a property for processOCIMessageReturn
, also as a string.
Next, run the XSDs you're interested in through xsd.exe using the /c
switch to generate your classes.
From there on, you will need to write code which instantiate and populate accordingly classes you've created in the second step. Serialize the "top" class into a string using an XmlSerializer and then assign that string to the property mentioned in the first step. You don't need to worry about encoding XML as a text node, since this will be taken care for you by the XML serializer built-in the framework.
Upvotes: 1