Why won't .NET deserialize my primitive array from a web service?

前端 未结 3 482
眼角桃花
眼角桃花 2020-12-18 07:23

Help! I have an Axis web service that is being consumed by a C# application. Everything works great, except that arrays of long values always come across as [0,0,0,0] - th

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-18 07:42

    Here's a more or less copy-pasted version of a blog post I wrote on the subject.

    Executive summary: You can either change the way .NET deserializes the result set (see Chris's solution above), or you can reconfigure Axis to serialize its results in a way that's compatible with the .NET SOAP implementation.

    If you go the latter route, here's how:

    ... the generated classes look and appear to function normally, but if you'll look at the deserialized array on the client (.NET/WCF) side you'll find that the array has been deserialized incorrectly, and all values in the array are 0. You'll have to manually look at the SOAP response returned by Axis to figure out what's wrong; here's a sample response (again, edited for clarity):

    
    
        
            
              
                
                
                
                
                
              
            
            5
            4
            3
            2
            1
       
    
    

    You'll notice that Axis does not generate values directly in the returned element, but instead references external elements for values. This might make sense when there are many references to relatively few discrete values, but whatever the case this is not properly handled by the WCF basicHttpBinding provider (and reportedly by gSOAP and classic .NET web references as well).

    It took me a while to find a solution: edit your Axis deployment's server-config.wsdd file and find the following parameter:

    
    

    Change it to false, then redeploy via the command line, which looks (under Windows) something like this:

    java -cp %AXISCLASSPATH% org.apache.axis.client.AdminClient server-config.wsdl 
    

    The web service's response should now be deserializable by your .NET client.

提交回复
热议问题