views:

232

answers:

2

I ran into a strange problem using a C# webservice client to call a ASP.NET 2.0 webservice. The service is a simple product search and returns an array of products matching a search term - see the relevant part of the WSDL file below.
My C# client is simply generated by adding a web reference in VS2010 (non-WCF) and for comparison I'm using an Axis 1.4 Java client.
Using the same search paramaters in both the C# and the Java client the call returns 50 products but in the C# client the result array has length 1 while the Java client shows up the correct 50 elements.

I am looking for suggestions how to locate the problem - I've tried the following:

  • Compare the XML returned by the webservice using a TCP/IP monitor: The XML looks identical C# vs. Java and contains the 50 products
  • Compare HTTP parameters using netcat: C# defaults to HTTP 1.1 while Axis 1.4 uses HTTP 1.0, but changing the C# client to use HTTP 1.0 as well does no change anything
  • Try SOAP 1.2 instead of SOAP 1.1: No effect
  • Try HttpGetProtocol, HttpPostProtocol instead of Soap

Any suggestions are highly appreciated.


EDIT: Full WSDL and generated code (Reference.cs) can be found here:
http://timmay.dk/Reference.txt
http://timmay.dk/Wsdl.txt

Simplified WSDL part:

      <s:element name="Search">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="SearchTerm" type="s:string" />
        <s:element minOccurs="0" maxOccurs="1" name="StartFrom" type="s:string" />
        <s:element minOccurs="0" maxOccurs="1" name="NumberToBeReturned" type="s:string" />
      </s:sequence>
    </s:complexType>
  </s:element>
  <s:element name="SearchResponse">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="SearchResult" type="tns:SearchResult" />
      </s:sequence>
    </s:complexType>
  </s:element>
  <s:complexType name="SearchResult">
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="Products" type="tns:ArrayOfResponseProduct" />
    </s:sequence>
  </s:complexType>
  <s:complexType name="ArrayOfResponseProduct">
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="unbounded" name="ResponseProduct" nillable="true" type="tns:ResponseProduct" />
    </s:sequence>
  </s:complexType>
  <s:complexType name="ResponseProduct">
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="Fields" type="tns:ArrayOfResponseField" />
    </s:sequence>
    <s:attribute name="id" type="s:string" />
  </s:complexType>
A: 

From the WSDL I gather that the maxOccurs is 1. So it seems that you should receive indeed only one SearchResult. However, that result itself should contain an object of type ArrayOfReponseProduct, which contains an unbounded amount of `ResponseProduct items. Maybe you are not looking deep enough?

Have you tried to check inside the debugger with the variable inspectors (Local, Auto, Immediate etc)? Is the object typed, or untyped, in which case you may need to cast it first to see the contents?

Abel
That's correct - you receive 1 SearchResult object and that one has the ArrayOfResponseProduct (SearchResult.Producst in the generated code).This one has length 1 i the C# code and length 50 in the Java code.The debugger shows 1 item as does prompting the Length property of the array.
Tim
@Tim: and may I assume you have inspected that one item for not being another level of an array or enumerator, as your WSDL suggests?
Abel
@Abel: Yes, that one item is just a "ResponseProduct" which consists of an array of properties. The XML looks like this: <Products> <ResponseProduct id="1330601"> <Fields> <Field> ...- each ResponseProduct item has a list of Fields.The single entry in the Products array I receive has "id" 1330601 just as it should according to the XML.Debugging the Java client yields the same structure, just with ... 50 items in the Products array.
Tim
A: 

It turned out that the culprit was the type of the return values - Response field

< s:complexType name="ResponseField">
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="Name" type="s:string" />
      <s:element minOccurs="0" maxOccurs="1" name="Value">
        <s:complexType>
          <s:sequence>
            <s:element ref="s:schema" />
            <s:any />
          </s:sequence>
        </s:complexType>
      </s:element>
    </s:sequence>
  </s:complexType>

This was pr default converted to a System.Data.DataSet - changing this to a simple string solved the problem. It seems that the unmarshalling failed in this case.

Tim