Axis2 always receives null parameters even if SOAP request is sent correctly?

Go To StackoverFlow.com

2

UPDATE: I HAVE SOLVED THIS PROBLEM NOW - PLEASE SCROLL TO BOTTOM FOR INFORMATION ABOUT FIX

Hi guys,

I have a web-service written in Java, hosted on an Axis2 / Tomcat / Apache server. My client software is written in C#.

I have had a few irritating problems with the way java2wsdl generates the wsdl file, which did cause me a few headaches early on, but with this problem I am completely stumped.

Basically what is happening is that the client sees the web service fine, and sends a perfectly valid (or at least, it looks valid to me) SOAP request with parameters.

On the server, the correct web method is executed, but the parameters are all null. My web service detects this and builds up a response, which the client receives and understands perfectly well.

My hunch is that Axis2 is falling flat on its face somewhere, but given the headaches I have had with java2wsdl, perhaps all I need is a change in my wsdl file.

Here is the wsdl file:

    <?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:axis2="http://stws/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ns0="http://stws/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://stws/">
    <wsdl:types>
        <xs:schema xmlns:ns="http://stws/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://stws/xsd">
            <xs:element name="GetGroups">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="GetGroupsResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ns0:Group"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:complexType name="Group">
                <xs:sequence>
                    <xs:element minOccurs="0" name="ID" type="xs:int"/>
                    <xs:element minOccurs="0" name="Name" nillable="true" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
            <xs:element name="GetMessages">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="groupids" type="xs:int"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="GetMessagesResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ns0:Message"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:complexType name="Message">
                <xs:sequence>
                    <xs:element minOccurs="0" name="date" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="group" type="xs:int"/>
                    <xs:element minOccurs="0" name="messageID" type="xs:int"/>
                    <xs:element minOccurs="0" name="text" nillable="true" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
        </xs:schema>
    </wsdl:types>
    <wsdl:message name="GetMessagesRequest">
        <wsdl:part name="parameters" element="ns0:GetMessages"/>
    </wsdl:message>
    <wsdl:message name="GetMessagesResponse">
        <wsdl:part name="parameters" element="ns0:GetMessagesResponse"/>
    </wsdl:message>
    <wsdl:message name="GetGroupsRequest">
        <wsdl:part name="parameters" element="ns0:GetGroups"/>
    </wsdl:message>
    <wsdl:message name="GetGroupsResponse">
        <wsdl:part name="parameters" element="ns0:GetGroupsResponse"/>
    </wsdl:message>
    <wsdl:portType name="MyProjectPortType">
        <wsdl:operation name="GetMessages">
            <wsdl:input message="axis2:GetMessagesRequest" wsaw:Action="urn:GetMessages"/>
            <wsdl:output message="axis2:GetMessagesResponse" wsaw:Action="urn:GetMessagesResponse"/>
        </wsdl:operation>
        <wsdl:operation name="GetGroups">
            <wsdl:input message="axis2:GetGroupsRequest" wsaw:Action="urn:GetGroups"/>
            <wsdl:output message="axis2:GetGroupsResponse" wsaw:Action="urn:GetGroupsResponse"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="MyProjectSOAP11Binding" type="axis2:MyProjectPortType">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <wsdl:operation name="GetMessages">
            <soap:operation soapAction="urn:GetMessages" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="GetGroups">
            <soap:operation soapAction="urn:GetGroups" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="MyProjectSOAP12Binding" type="axis2:MyProjectPortType">
        <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
        <wsdl:operation name="GetMessages">
            <soap12:operation soapAction="urn:GetMessages" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="GetGroups">
            <soap12:operation soapAction="urn:GetGroups" style="document"/>
            <wsdl:input>
                <soap12:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap12:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="MyProjectHttpBinding" type="axis2:MyProjectPortType">
        <http:binding verb="POST"/>
        <wsdl:operation name="GetMessages">
            <http:operation location="MyProject/GetMessages"/>
            <wsdl:input>
                <mime:content type="text/xml" part="GetMessages"/>
            </wsdl:input>
            <wsdl:output>
                <mime:content type="text/xml" part="GetMessages"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="GetGroups">
            <http:operation location="MyProject/GetGroups"/>
            <wsdl:input>
                <mime:content type="text/xml" part="GetGroups"/>
            </wsdl:input>
            <wsdl:output>
                <mime:content type="text/xml" part="GetGroups"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="MyProject">
        <wsdl:port name="MyProjectSOAP11port_http" binding="axis2:MyProjectSOAP11Binding">
            <soap:address location="http://localhost:8080/axis2/services/MyProject"/>
        </wsdl:port>
        <wsdl:port name="MyProjectSOAP12port_http" binding="axis2:MyProjectSOAP12Binding">
            <soap12:address location="http://localhost:8080/axis2/services/MyProject"/>
        </wsdl:port>
        <wsdl:port name="MyProjectHttpport" binding="axis2:MyProjectHttpBinding">
            <http:address location="http://localhost:8080/axis2/services/MyProject"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

And here is a sample request and response:

Request:

<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soap:Body>
    <GetGroups xmlns="http://stws/xsd">
      <serialcode>123456-654321</serialcode>
    </GetGroups>
  </soap:Body>
</soap:Envelope>

Response

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
  <soapenv:Body>
    <GetGroupsResponse xmlns="http://stws/xsd">
      <return>
        <ID>-101</ID>
        <name>ERROR: Empty Serial</name>
      </return>
    </GetGroupsResponse>
  </soapenv:Body>
</soapenv:Envelope>

Does anybody have any idea what could be going wrong?

The error message in the response can only be sent when the serialcode parameter in the request is empty / null, so I'm guessing there is something wrong with how Axis2 is reading my parameters.

Any help is much appreciated.

============================================================

HOW TO FIX THIS:

This is in response to Aldo's request for more information about how I fixed this problem.

I am unsure of why this fix works - perhaps it is just a bug in Axis2 or something. Either way, YMMV as I don't know whether the problem was caused by my setup or something else. All I can say is that by doing the following, everything started working.

Anyway, the auto-generated WSDL file creates complex-element types for web requests and their parameters, even when the only parameters are simple types such as strings or integers. What I did was go through and create the correct simple-type tags for parameters (such as 'serialcode' or 'date-string'), then replace the references to the complex types elsewhere in the WSDL file with references to the simple types.

An example is below:

Auto Generated WSDL method and parameters

<!--Requests-->    
<wsdl:message name="RegisterClientRequest">
    <wsdl:part name="parameters" element="ns0:RegisterClient"/>
</wsdl:message>
<wsdl:message name="GetGroupsRequest">
    <wsdl:part name="parameters" element="ns0:GetGroups"/>
</wsdl:message>

<!--Parameters-->
<xs:element name="RegisterClient">
    <xs:complexType>
        <xs:sequence>
           <xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:element name="GetGroups">
    <xs:complexType>
        <xs:sequence>
            <xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
 </xs:element>

Basically what you should do is discard the auto-generated parameters and create simple-types. You then modify the 'request' tags to use 'type' rather than 'element', and use your newly created simple-types.

Modified / Fixed WSDL

<!--Requests-->    
<wsdl:message name="RegisterClientRequest">
    <wsdl:part name="parameters" type="ns0:SerialCode"/>
</wsdl:message>
<wsdl:message name="GetGroupsRequest">
    <wsdl:part name="parameters" type="ns0:SerialCode"/>
</wsdl:message>

<!--Parameters-->
<xs:simpleType name="SerialCode">
    <xs:restriction base="xs:string"/>
</xs:simpleType>

Obviously it depends on what your parameters actually are. In my case they are all standard simple types such as strings and integers. If you are passing more than one parameter, you may need to play around by retaining the auto-generated elements but making sure that the element refers to simple types rather than just including the type attribute as 'xs:string' or something of that nature.

Apologies I can't be more clear on this, but as I said earlier - I don't know why this works.

One final thing: By removing the 'element' reference attribute in the request tags - you may receive a parser warning in your Axis2 logs. So far this has not caused me any problems, but it's something to be aware of in case you run into trouble.

2009-06-16 10:04
by Beardy
What component is doing the validation and generating that error message? If it's your code, can you verify that the request data is missing by the time it gets that far - skaffman 2009-06-16 11:58
The actual web methods themselves perform a quick check (indeed, the only reason the check exists in the first place is because I was getting null returns - this just gives me an easy way to acknowledge that the input was null!).

Simple unit testing on the web service code does not produce this problem, and Axis2's own SOAPMonitor shows that the client is indeed sending the required parameters - but for some reason the parameters are nullified by the time Axis2 invokes the web methods - Beardy 2009-06-16 12:44



1

I solved this issue by going through my WSDL file and, wherever possible, breaking down elements into their simple type counterparts and updating the references between the XML elements accordingly.

I am unsure why this works, but it has solved my problem anyway.

2009-06-29 13:00
by Beardy


1

If you had a complex attribute this is how you could do it

Before

 <xs:element name="getMyMenu">
            <xs:complexType>
                <xs:sequence>
                    <xs:element minOccurs="0" name="number" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="var2" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="var3" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="var4" nillable="true" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>

After

            <xs:complexType name="getMyMenu">
                <xs:sequence>
                    <xs:element minOccurs="0" name="number" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="var2" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="var3" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="var4" nillable="true" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>

And then change this

<wsdl:message name="getMyMenuRequest">
    <wsdl:part name="parameters" type="ns0:getUssdMenu"/>
</wsdl:message>

To

<wsdl:message name="getMyMenuRequest">
    <wsdl:part name="parameters" type="ns:getUssdMenu"/>
</wsdl:message>

That should be it! It did it for me....

2010-11-04 08:06
by Ngetha


0

This is just a hunch, but maybe you're having a namespace issue. If you focus on this part of the wsdl, notice that your parameter has an "ns0" namespace for the elements, but in your operations defined later, it looks like you're using an "axis2" namespace. With all of my Axis2 generated WSDLs, these two namespaces are the same.

<wsdl:message name="GetMessagesRequest">
    <wsdl:part name="parameters" element="ns0:GetMessages"/>
</wsdl:message>
<wsdl:message name="GetMessagesResponse">
    <wsdl:part name="parameters" element="ns0:GetMessagesResponse"/>
</wsdl:message>
<wsdl:message name="GetGroupsRequest">
    <wsdl:part name="parameters" element="ns0:GetGroups"/>
</wsdl:message>
<wsdl:message name="GetGroupsResponse">
    <wsdl:part name="parameters" element="ns0:GetGroupsResponse"/>
</wsdl:message>

<wsdl:portType name="MyProjectPortType">
    <wsdl:operation name="GetMessages">
        <wsdl:input message="axis2:GetMessagesRequest" wsaw:Action="urn:GetMessages"/>
        <wsdl:output message="axis2:GetMessagesResponse" wsaw:Action="urn:GetMessagesResponse"/>
    </wsdl:operation>
    <wsdl:operation name="GetGroups">
        <wsdl:input message="axis2:GetGroupsRequest" wsaw:Action="urn:GetGroups"/>
        <wsdl:output message="axis2:GetGroupsResponse" wsaw:Action="urn:GetGroupsResponse"/>
    </wsdl:operation>
</wsdl:portType>

Another thing you can check is to verify that the wsdl you got from java2wsdl is the same that is generated by axis2. Unless you have changed the default setting of "useoriginalwsdl" in your services.xml, these wsdls can "look" different. I never had to perform a java2wsdl manually to get my webservice to function correctly...

So basically, hit your service URL in a browser and tack on the ?wsdl at the end of the url...you should get a wsdl for comparison sake.

Also, have your client generate stubs from the server's wsdl instead of one that is generated by java2wsdl (assuming you originally used the wsdl from java2wsdl). Again, we never had to pass a manually generated wsdl around to anyone...they just simply consumed the dynamically generated one from the server...

2009-06-16 13:54
by Tim Reddy
I had thought that - but the axis2 namespace is automatically generated by java2wsdl. I would have thought the fact that the web method gets called successfully would mean it couldn't be a namespace issue, but I'll give it a go - Beardy 2009-06-16 14:15
After changing axis2 to ns0, the client could no longer interpret returned values, so I don't think that's the problem.

Thanks for your input anyway - Beardy 2009-06-16 14:19



0

Have you tried to send a request like this?

<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soap:Body>
    <request>
      <GetGroups xmlns="http://stws/xsd">
        <serialcode>123456-654321</serialcode>
      </GetGroups>
    </request>
  </soap:Body>
</soap:Envelope>

All my requests have the request tag before the actual request parameters.

2009-06-26 13:20
by NoName
Thanks for taking the time to reply osrichie - but I have managed to solve the problem by breaking down elements into their simple type equivalents wherever possible. I don't understand why this works (bug in Axis2?), but it seems to remove the problem - Beardy 2009-06-29 12:59


0

try this: 123456-654321

Put xmlns="" into the parameter tag. I have the same problem and I don't know what I can modify in order to receive the parameter whitout the xmlnx.

2009-08-24 15:34
by NoName


0

I have another fix. I eventually discovered that if I didn't let my IDE (Netbeans 6.8) generate the WSDL then the web service worked. Alternatively if I deleted it, unticked the generate option and re-deployed then it worked.

Comparing a Netbeans generated WSDL to a server generated one I noticed the following differences :

  • xmlns:ns0="http:///xsd"
  • target namespace at the end of the wsdl:definitions tag had a trailing slash
  • ns0 used to choose the elements that make up the wsdl:message tag

Removing all these and re-deploying worked!

2010-03-04 00:36
by Ben Howell-Thomas
Ads