Mark Kadlec
Mark Kadlec

Reputation: 8460

Passing complex type parameters into a Web Service

I have a WSDL endpoint which I've added to my Project as a Service Reference called ContentService, works out fine.

Then in my code, I'm declaring the client, and the associated request, UnitInfo like this:

  // Both of these declarations work fine    
  ContentService.ContentServiceClient client = new   ContentService.ContentServiceClient();
  ContentService.UnitInfo request = new ContentService.UnitInfo();

I need to pass in the following info though:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
    <Body>
        <UnitInfo xmlns="http://www.acme.com/acme/2007/02">
            <!-- Optional -->
            <POS>
                <!-- Optional -->
                <Source>
                </Source>
            </POS>
            <!-- Optional -->
            <UnitInfos>
                <!-- Optional -->
                <Units HowMany="?">
                    <!-- Optional -->
                    <Amenities/>
                    <!-- Optional -->
                </Units>
            </UnitInfos>
        </UnitInfo>
    </Body>
</Envelope>

The problem is that my request variable has null for the UnitInfos property, how can I set the 'HowMany' attribute on the Units section before sending. Also, how do I send the request to the endpoint?

All the examples on the web show a simple add where you are sending two ints, but here I need to send a more complicated structure over.

Upvotes: 0

Views: 932

Answers (1)

ie.
ie.

Reputation: 6101

First of all you usually see no diference between sending ints or something more complecated:

client.Send(new ContentService.UnitInfo());

Second. As you wrote <UnitInfos> and it will not exist in envelope, if null is set.-

Upvotes: 1

Related Questions