axis 2 web service:使用http绑定发出null参数

时间:2010-09-13 18:08:21

标签: java null axis2 wshttpbinding

我正在尝试使用axis2开发一个Web服务。问题是我没有在http绑定的url中获取传递的参数。

这是我的service.xml:

<parameter name="ServiceClass">my.package.MyClass
    </parameter>
    <operation name="getUser">
        <messageReceiver class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
    </operation>
    <parameter name="useOriginalwsdl">true</parameter>

这是我简化的wsdl:

<definitions ...>
        <types>
            <schema ...>
                <complexType name="User">
                    <sequence>
                        <element name="id" type="string"/>
                        <element name="age" type="int"/>
                    </sequence>
                </complexType>
                <element name="getUser">
                    <complexType>
                        <sequence>
                            <element name="id" type="xs:string" form="unqualified" />
                        </sequence>
                    </complexType>
                </element>
                <element name="getUserResponse">
                    <complexType>
                        <sequence>
                            <element name="user" nillable="true"
                                type="user" />
                        </sequence>
                    </complexType>
                </element>
            </schema>
        </types>


        <message name="getUserRequest">
            <part name="parameters" element="getUser" />
        </message>
        <message name="getUserResponse">
            <part name="parameters" element="getUserResponse" />
        </message>

        <portType name="testPortType">
            <operation name="getUser">
                <input message="getUserRequest"
                    Action="urn:getUser" />
                <output message="getUserResponse"
                    Action="urn:getUserResponse" />
            </operation>
        </portType>

        <binding name="testHttpBinding" type="testPortType">
            <binding verb="GET" />
            <operation name="getUser">
                <http:operation location="getUser" />
                <input>
                    <http:urlEncoded />
                <input>
                <output>
                    <mime:content type="text/xml" />
                </output>
            </operation>
        </binding>
        <service name="test">
            <port name="testHttpEndpoint" binding="testHttpBinding">
                <address
                    location="http://localhost:8080/axis2/services/test.testHttpEndpoint/" />
            </port>
        </service>
    </definitions>

最后是my.package.MyClass:

public final class MyClass {

 public User getUser(String id) {
  //Do something
 }
}

当我使用请求http://urlToService/getUser?id=test调用服务时,我输入getUser(String id)但id为null。

有人知道我该如何解决这个问题?

谢谢

1 个答案:

答案 0 :(得分:0)

事实上我做错了什么。

在MyClass中,我不应该这样做:

public User getUser(String id){
}

public User getUser(GetUser getUser){
}

写在wsdl文件中。