<p>I am writing a C# client that calls a web service written in Java (by another person).  I have added a web reference to my client and I'm able to call methods in the web service ok.</p>

<p>The service was changed to return an array of objects, and the client does not properly parse the returned SOAP message.</p>

<pre><code>MyResponse[] MyFunc(string p)

class MyResponse
{
    long id;
    string reason;
}
</code></pre>

<p>When my generated C# proxy calls the web service (using SoapHttpClientProtocol.Invoke), I am expecting a MyResponse[] array with length of 1, ie a single element.  What I am getting after the Invoke call is an element with id=0 and reason=null, regardless of what the service actually returns.  Using a packet sniffer, I can see that the service is returning what appears to be a legitimate soap message with id and reason set to non-null values.</p>

<p>Is there some trick to getting a C# client to call a Java web service that returns someobject[] ?  I will work on getting a sanitized demo if necessary.</p>

<p><strong>Edit</strong>: This is a web reference via "Add Web Reference...".  VS 2005, .NET 3.0.</p>

[{'answer_id': 64913, 'author': 'Xian', 'author_id': 4642, 'author_profile': 'https://Stackoverflow.com/users/4642', 'pm_score': 3, 'selected': True, 'text': '<p>It has been a while, but I seem to remember having trouble with the slight differences in how default namespaces were handled between .Net and Java web services.</p>\n\n<p>Double check the generated c# proxy class and any namespaces declared within (especially the defaults xmlns=""), against what the Java service is expecting.  There will be probably be very subtle differences which you will have to recreate.</p>\n\n<p>If this is the case then you will to provide more namespace declarations in the c# attributes.</p>\n'}, {'answer_id': 66296, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>From your question, it looks like you had the client working at one point, and then the service was changed to return an array. Make sure you re-generate the proxy so the returned SOAP message is deserialized on the client. It wasn't clear you had done this - just making sure.</p>\n"}, {'answer_id': 66834, 'author': 'David Chappelle', 'author_id': 7475, 'author_profile': 'https://Stackoverflow.com/users/7475', 'pm_score': 3, 'selected': False, 'text': '<p>Thanks to Xian, I have a solution.</p>\n\n<p>The wsdl for the service included a line</p>\n\n<pre><code>&lt;import namespace="http://mynamespace.company.com"/&gt;\n</code></pre>\n\n<p>The soap that the client sent to the server had the following attribute on all data elements:</p>\n\n<pre><code>xmlns="http://mynamespace.company.com"\n</code></pre>\n\n<p>But the xml payload of the response (from the service back to the client) did <em>not</em> have this namespace included.  By tinkering with the HTTP response (which I obtained with <strong>WireShark</strong>), I observed that the .NET proxy class correctly picked up the MyResponse values if I forced the xmlns attribute on every returned data element.</p>\n\n<p>Short of changing the service, which I don\'t control, the workaround is to edit the VS generated proxy class (eg Reference.cs) and look for lines like this:</p>\n\n<pre><code>[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://mynamespace.company.com")]\npublic partial class MyResponse {\n</code></pre>\n\n<p>and comment out the XmlType attribute line.  This will tell the CLR to look for response elements in the default namespace rather than the one specied in the wsdl.  You have to redo this whenever you update the reference, but at least it works.</p>\n'}]
['https://Stackoverflow.com/questions/64833', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/7475/']