title: Axis2 always receives null parameters even if SOAP request is sent correctly?
body: <p>I have a web-service written in Java, hosted on an Axis2 / Tomcat / Apache server. My client software is written in C#.</p>
  <p>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.</p>
  <p>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.</p>
  <p>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.</p>
  <p>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.</p>
  <p>Here is the wsdl file:</p>
  <pre><code>    &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;wsdl:definitions xmlns:wsdl=&quot;http://schemas.xmlsoap.org/wsdl/&quot; xmlns:axis2=&quot;http://stws/&quot; xmlns:ns1=&quot;http://org.apache.axis2/xsd&quot; xmlns:wsaw=&quot;http://www.w3.org/2006/05/addressing/wsdl&quot; xmlns:http=&quot;http://schemas.xmlsoap.org/wsdl/http/&quot; xmlns:ns0=&quot;http://stws/xsd&quot; xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:mime=&quot;http://schemas.xmlsoap.org/wsdl/mime/&quot; xmlns:soap=&quot;http://schemas.xmlsoap.org/wsdl/soap/&quot; xmlns:soap12=&quot;http://schemas.xmlsoap.org/wsdl/soap12/&quot; targetNamespace=&quot;http://stws/&quot;&gt;
      &lt;wsdl:types&gt;
          &lt;xs:schema xmlns:ns=&quot;http://stws/xsd&quot; attributeFormDefault=&quot;qualified&quot; elementFormDefault=&quot;qualified&quot; targetNamespace=&quot;http://stws/xsd&quot;&gt;
              &lt;xs:element name=&quot;GetGroups&quot;&gt;
                  &lt;xs:complexType&gt;
                      &lt;xs:sequence&gt;
                          &lt;xs:element minOccurs=&quot;0&quot; name=&quot;serialcode&quot; nillable=&quot;true&quot; type=&quot;xs:string&quot;/&gt;
                      &lt;/xs:sequence&gt;
                  &lt;/xs:complexType&gt;
              &lt;/xs:element&gt;
              &lt;xs:element name=&quot;GetGroupsResponse&quot;&gt;
                  &lt;xs:complexType&gt;
                      &lt;xs:sequence&gt;
                          &lt;xs:element maxOccurs=&quot;unbounded&quot; minOccurs=&quot;0&quot; name=&quot;return&quot; nillable=&quot;true&quot; type=&quot;ns0:Group&quot;/&gt;
                      &lt;/xs:sequence&gt;
                  &lt;/xs:complexType&gt;
              &lt;/xs:element&gt;
              &lt;xs:complexType name=&quot;Group&quot;&gt;
                  &lt;xs:sequence&gt;
                      &lt;xs:element minOccurs=&quot;0&quot; name=&quot;ID&quot; type=&quot;xs:int&quot;/&gt;
                      &lt;xs:element minOccurs=&quot;0&quot; name=&quot;Name&quot; nillable=&quot;true&quot; type=&quot;xs:string&quot;/&gt;
                  &lt;/xs:sequence&gt;
              &lt;/xs:complexType&gt;
              &lt;xs:element name=&quot;GetMessages&quot;&gt;
                  &lt;xs:complexType&gt;
                      &lt;xs:sequence&gt;
                          &lt;xs:element minOccurs=&quot;0&quot; name=&quot;serialcode&quot; nillable=&quot;true&quot; type=&quot;xs:string&quot;/&gt;
                          &lt;xs:element maxOccurs=&quot;unbounded&quot; minOccurs=&quot;0&quot; name=&quot;groupids&quot; type=&quot;xs:int&quot;/&gt;
                      &lt;/xs:sequence&gt;
                  &lt;/xs:complexType&gt;
              &lt;/xs:element&gt;
              &lt;xs:element name=&quot;GetMessagesResponse&quot;&gt;
                  &lt;xs:complexType&gt;
                      &lt;xs:sequence&gt;
                          &lt;xs:element maxOccurs=&quot;unbounded&quot; minOccurs=&quot;0&quot; name=&quot;return&quot; nillable=&quot;true&quot; type=&quot;ns0:Message&quot;/&gt;
                      &lt;/xs:sequence&gt;
                  &lt;/xs:complexType&gt;
              &lt;/xs:element&gt;
              &lt;xs:complexType name=&quot;Message&quot;&gt;
                  &lt;xs:sequence&gt;
                      &lt;xs:element minOccurs=&quot;0&quot; name=&quot;date&quot; nillable=&quot;true&quot; type=&quot;xs:string&quot;/&gt;
                      &lt;xs:element minOccurs=&quot;0&quot; name=&quot;group&quot; type=&quot;xs:int&quot;/&gt;
                      &lt;xs:element minOccurs=&quot;0&quot; name=&quot;messageID&quot; type=&quot;xs:int&quot;/&gt;
                      &lt;xs:element minOccurs=&quot;0&quot; name=&quot;text&quot; nillable=&quot;true&quot; type=&quot;xs:string&quot;/&gt;
                  &lt;/xs:sequence&gt;
              &lt;/xs:complexType&gt;
          &lt;/xs:schema&gt;
      &lt;/wsdl:types&gt;
      &lt;wsdl:message name=&quot;GetMessagesRequest&quot;&gt;
          &lt;wsdl:part name=&quot;parameters&quot; element=&quot;ns0:GetMessages&quot;/&gt;
      &lt;/wsdl:message&gt;
      &lt;wsdl:message name=&quot;GetMessagesResponse&quot;&gt;
          &lt;wsdl:part name=&quot;parameters&quot; element=&quot;ns0:GetMessagesResponse&quot;/&gt;
      &lt;/wsdl:message&gt;
      &lt;wsdl:message name=&quot;GetGroupsRequest&quot;&gt;
          &lt;wsdl:part name=&quot;parameters&quot; element=&quot;ns0:GetGroups&quot;/&gt;
      &lt;/wsdl:message&gt;
      &lt;wsdl:message name=&quot;GetGroupsResponse&quot;&gt;
          &lt;wsdl:part name=&quot;parameters&quot; element=&quot;ns0:GetGroupsResponse&quot;/&gt;
      &lt;/wsdl:message&gt;
      &lt;wsdl:portType name=&quot;MyProjectPortType&quot;&gt;
          &lt;wsdl:operation name=&quot;GetMessages&quot;&gt;
              &lt;wsdl:input message=&quot;axis2:GetMessagesRequest&quot; wsaw:Action=&quot;urn:GetMessages&quot;/&gt;
              &lt;wsdl:output message=&quot;axis2:GetMessagesResponse&quot; wsaw:Action=&quot;urn:GetMessagesResponse&quot;/&gt;
          &lt;/wsdl:operation&gt;
          &lt;wsdl:operation name=&quot;GetGroups&quot;&gt;
              &lt;wsdl:input message=&quot;axis2:GetGroupsRequest&quot; wsaw:Action=&quot;urn:GetGroups&quot;/&gt;
              &lt;wsdl:output message=&quot;axis2:GetGroupsResponse&quot; wsaw:Action=&quot;urn:GetGroupsResponse&quot;/&gt;
          &lt;/wsdl:operation&gt;
      &lt;/wsdl:portType&gt;
      &lt;wsdl:binding name=&quot;MyProjectSOAP11Binding&quot; type=&quot;axis2:MyProjectPortType&quot;&gt;
          &lt;soap:binding transport=&quot;http://schemas.xmlsoap.org/soap/http&quot; style=&quot;document&quot;/&gt;
          &lt;wsdl:operation name=&quot;GetMessages&quot;&gt;
              &lt;soap:operation soapAction=&quot;urn:GetMessages&quot; style=&quot;document&quot;/&gt;
              &lt;wsdl:input&gt;
                  &lt;soap:body use=&quot;literal&quot;/&gt;
              &lt;/wsdl:input&gt;
              &lt;wsdl:output&gt;
                  &lt;soap:body use=&quot;literal&quot;/&gt;
              &lt;/wsdl:output&gt;
          &lt;/wsdl:operation&gt;
          &lt;wsdl:operation name=&quot;GetGroups&quot;&gt;
              &lt;soap:operation soapAction=&quot;urn:GetGroups&quot; style=&quot;document&quot;/&gt;
              &lt;wsdl:input&gt;
                  &lt;soap:body use=&quot;literal&quot;/&gt;
              &lt;/wsdl:input&gt;
              &lt;wsdl:output&gt;
                  &lt;soap:body use=&quot;literal&quot;/&gt;
              &lt;/wsdl:output&gt;
          &lt;/wsdl:operation&gt;
      &lt;/wsdl:binding&gt;
      &lt;wsdl:binding name=&quot;MyProjectSOAP12Binding&quot; type=&quot;axis2:MyProjectPortType&quot;&gt;
          &lt;soap12:binding transport=&quot;http://schemas.xmlsoap.org/soap/http&quot; style=&quot;document&quot;/&gt;
          &lt;wsdl:operation name=&quot;GetMessages&quot;&gt;
              &lt;soap12:operation soapAction=&quot;urn:GetMessages&quot; style=&quot;document&quot;/&gt;
              &lt;wsdl:input&gt;
                  &lt;soap12:body use=&quot;literal&quot;/&gt;
              &lt;/wsdl:input&gt;
              &lt;wsdl:output&gt;
                  &lt;soap12:body use=&quot;literal&quot;/&gt;
              &lt;/wsdl:output&gt;
          &lt;/wsdl:operation&gt;
          &lt;wsdl:operation name=&quot;GetGroups&quot;&gt;
              &lt;soap12:operation soapAction=&quot;urn:GetGroups&quot; style=&quot;document&quot;/&gt;
              &lt;wsdl:input&gt;
                  &lt;soap12:body use=&quot;literal&quot;/&gt;
              &lt;/wsdl:input&gt;
              &lt;wsdl:output&gt;
                  &lt;soap12:body use=&quot;literal&quot;/&gt;
              &lt;/wsdl:output&gt;
          &lt;/wsdl:operation&gt;
      &lt;/wsdl:binding&gt;
      &lt;wsdl:binding name=&quot;MyProjectHttpBinding&quot; type=&quot;axis2:MyProjectPortType&quot;&gt;
          &lt;http:binding verb=&quot;POST&quot;/&gt;
          &lt;wsdl:operation name=&quot;GetMessages&quot;&gt;
              &lt;http:operation location=&quot;MyProject/GetMessages&quot;/&gt;
              &lt;wsdl:input&gt;
                  &lt;mime:content type=&quot;text/xml&quot; part=&quot;GetMessages&quot;/&gt;
              &lt;/wsdl:input&gt;
              &lt;wsdl:output&gt;
                  &lt;mime:content type=&quot;text/xml&quot; part=&quot;GetMessages&quot;/&gt;
              &lt;/wsdl:output&gt;
          &lt;/wsdl:operation&gt;
          &lt;wsdl:operation name=&quot;GetGroups&quot;&gt;
              &lt;http:operation location=&quot;MyProject/GetGroups&quot;/&gt;
              &lt;wsdl:input&gt;
                  &lt;mime:content type=&quot;text/xml&quot; part=&quot;GetGroups&quot;/&gt;
              &lt;/wsdl:input&gt;
              &lt;wsdl:output&gt;
                  &lt;mime:content type=&quot;text/xml&quot; part=&quot;GetGroups&quot;/&gt;
              &lt;/wsdl:output&gt;
          &lt;/wsdl:operation&gt;
      &lt;/wsdl:binding&gt;
      &lt;wsdl:service name=&quot;MyProject&quot;&gt;
          &lt;wsdl:port name=&quot;MyProjectSOAP11port_http&quot; binding=&quot;axis2:MyProjectSOAP11Binding&quot;&gt;
              &lt;soap:address location=&quot;http://localhost:8080/axis2/services/MyProject&quot;/&gt;
          &lt;/wsdl:port&gt;
          &lt;wsdl:port name=&quot;MyProjectSOAP12port_http&quot; binding=&quot;axis2:MyProjectSOAP12Binding&quot;&gt;
              &lt;soap12:address location=&quot;http://localhost:8080/axis2/services/MyProject&quot;/&gt;
          &lt;/wsdl:port&gt;
          &lt;wsdl:port name=&quot;MyProjectHttpport&quot; binding=&quot;axis2:MyProjectHttpBinding&quot;&gt;
              &lt;http:address location=&quot;http://localhost:8080/axis2/services/MyProject&quot;/&gt;
          &lt;/wsdl:port&gt;
      &lt;/wsdl:service&gt;
  &lt;/wsdl:definitions&gt;
  </code></pre>
  <p>And here is a sample request and response:</p>
  <p>Request:</p>
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;soap:Envelope xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;
    &lt;soap:Body&gt;
      &lt;GetGroups xmlns=&quot;http://stws/xsd&quot;&gt;
        &lt;serialcode&gt;123456-654321&lt;/serialcode&gt;
      &lt;/GetGroups&gt;
    &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>
  <p>Response</p>
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
    &lt;soapenv:Body&gt;
      &lt;GetGroupsResponse xmlns=&quot;http://stws/xsd&quot;&gt;
        &lt;return&gt;
          &lt;ID&gt;-101&lt;/ID&gt;
          &lt;name&gt;ERROR: Empty Serial&lt;/name&gt;
        &lt;/return&gt;
      &lt;/GetGroupsResponse&gt;
    &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>
  <p>Does anybody have any idea what could be going wrong?</p>
  <p>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.</p>
  <p>============================================================</p>
  <p>How to fix this:</p>
  <p>This is in response to Aldo's request for more information about how I fixed this problem.</p>
  <p>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.</p>
  <p>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.</p>
  <p>An example is below:</p>
  <p><strong>Auto Generated WSDL method and parameters</strong></p>
  <pre><code>&lt;!--Requests--&gt;    
  &lt;wsdl:message name=&quot;RegisterClientRequest&quot;&gt;
      &lt;wsdl:part name=&quot;parameters&quot; element=&quot;ns0:RegisterClient&quot;/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name=&quot;GetGroupsRequest&quot;&gt;
      &lt;wsdl:part name=&quot;parameters&quot; element=&quot;ns0:GetGroups&quot;/&gt;
  &lt;/wsdl:message&gt;
  
  &lt;!--Parameters--&gt;
  &lt;xs:element name=&quot;RegisterClient&quot;&gt;
      &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
             &lt;xs:element minOccurs=&quot;0&quot; name=&quot;serialcode&quot; nillable=&quot;true&quot; type=&quot;xs:string&quot;/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  &lt;xs:element name=&quot;GetGroups&quot;&gt;
      &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element minOccurs=&quot;0&quot; name=&quot;serialcode&quot; nillable=&quot;true&quot; type=&quot;xs:string&quot;/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
   &lt;/xs:element&gt;
  </code></pre>
  <p>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.</p>
  <p><strong>Modified / Fixed WSDL</strong></p>
  <pre><code>&lt;!--Requests--&gt;    
  &lt;wsdl:message name=&quot;RegisterClientRequest&quot;&gt;
      &lt;wsdl:part name=&quot;parameters&quot; type=&quot;ns0:SerialCode&quot;/&gt;
  &lt;/wsdl:message&gt;
  &lt;wsdl:message name=&quot;GetGroupsRequest&quot;&gt;
      &lt;wsdl:part name=&quot;parameters&quot; type=&quot;ns0:SerialCode&quot;/&gt;
  &lt;/wsdl:message&gt;
  
  &lt;!--Parameters--&gt;
  &lt;xs:simpleType name=&quot;SerialCode&quot;&gt;
      &lt;xs:restriction base=&quot;xs:string&quot;/&gt;
  &lt;/xs:simpleType&gt;
  </code></pre>
  <p>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.</p>
  <p>Apologies I can't be more clear on this, but as I said earlier - I don't know why this works.</p>
  <p>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.</p>