Problem when switching from SoapClient to WebServicesClientProtocol

From: Wil Rodriguez (loopback_at_wilrod.com)
Date: 08/31/04


Date: Mon, 30 Aug 2004 17:46:17 -0700

I have a working C# class library that acts as a soap client. It was
implemented by extending the SoapClient object which gave me full control
over the formatting of the soap body:

    public class InventoryProxy : SoapClient
    { ...working code goes here...}

The vendor providing the web service will be requiring that all soap
messages (requests) be digitally signed, and later on also encrypted. So,
I've switched the base class for my library from SoapClient to
Microsoft.Web.Services2.WebServicesClientProtocol. The only problem that
I've run into so far is trying to get the message body formatted properly.
It all boils down to the "this.invoke()" method requiring an object array
and me not being able to figure out how to populate this array such that the
resulting soap body looks like this:

<soap:Body>
<InventoryRequest xmlns="Vendor.WebServices/Inventory>
  <Widgets>
    <Widget DeptId="2">Hammer</Widget>
    <Widget DeptId="2">Nail</Widget>
  </Widgets>
</InventoryRequest>
</soap:Body>

The closest I've gotten so far has been passing in a string array that gets
cast as an object array when calling the this.invoke() method:

//populate the test widgets array
string[] widgets = new string[] {"<Widget DeptId=\"2\">Hammer</Widget>",
"<Widget DeptId=\"2\">Nail</Widget>"};

//pass the array into the invoking function
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://my.vendor
.com/Inventory.asmx", RequestNamespace="Vendor.WebServices/Inventory",
ResponseElementName="InventoryResponse",
ResponseNamespace="Vendor.WebServices/Inventory",
Use=System.Web.Services.Description.SoapBindingUse.Literal,
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
public object[]
InventoryRequest([System.Xml.Serialization.XmlArrayAttribute(IsNullable=true
)] [System.Xml.Serialization.XmlArrayItemAttribute("Widget",
IsNullable=false)] string[] widgets) {
    return this.Invoke("InventoryRequest", new object[] {widgets});
}

But, when I trace the client input the soap body looks like this (and is
rejected by the web service):

<soap:Body>
 <InventoryRequest xmlns="Vendor.WebServices/Inventory">
  <Widgets>
    <Widget>&lt;Widget DeptId="2" &gt;Hammer&lt;/Widget&gt;</Widget>
    <Widget>&lt;Widget DeptId="2"&gt;Nail&lt;/Widget&gt;</Widget>
  </Widgets>
 </InventoryRequest>
</soap:Body>

It looks like the parameters in the Widgets[] array are treated as Inner
Text. If I just put the product name in the string array (i.e. string[]
widgets = new string[] {"Hammer", "Nail"};) then I get XML elements that
look normal, but then I'm missing the required DeptId attributes for each
Widget element:

<soap:Body>
 <InventoryRequest xmlns="Vendor.WebServices/Inventory">
  <Widgets>
    <Widget>Hammer</Widget>
    <Widget>Nail</Widget>
  </Widgets>
 </InventoryRequest>
</soap:Body>

Yes, I am a still a newbie, so any help/pointers on what I'm doing wrong or
how I can better control the formatting of the message body would be highly
appreciated.

Thanks,

Wil



Relevant Pages

  • Re: How to do: Web Services returning a class that inherits arrayl
    ... Array types can be defined in the soap schema. ... I have a class called CartLine and I try to return this class in a Web ... The proxy reference doesn't contain any information even though I use the ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • saving state via
    ... I am trying to find a 'best practice' method for saving / loading ... saving my application state as an array: ... "bad window path name" no matter what I pass in to it. ... Subject: tcl/tk:saving state of widgets?? ...
    (comp.lang.tcl)
  • array of Tkinter variables?
    ... I was hoping that I could use an array ... of StringVar variables to attach to these widgets, ... The University of Texas at Austin ...
    (comp.lang.python)
  • Re: Class in a Class
    ... Because a strongly typed collection of Nodes is NOT a LinkedList! ... an array of Widgets ... allowing you to create strongly typed linked lists! ...
    (microsoft.public.dotnet.languages.vb)
  • Re: ttk::checkbutton - I think, its a bug
    ... value for those widgets that implement the getter. ... linked to an array entry (with a dedicated array for ... for a long time whereby it basically did not work ...
    (comp.lang.tcl)