WebService方法始终在请求中接收null

时间:2011-03-25 13:40:33

标签: java web-services jboss

我通过方法搜索在JBoss上运行Web服务。

@WebService(serviceName = "MyService", portName = "MyServicePort", name = "MyService", targetNamespace = "http://example.com/MyService", wsdlLocation = "wsdl/myService.wsdl")
@Stateless
@TransactionManagement(TransactionManagementType.BEAN)
public class MyWebServiceBean extends MyService {
    @Override
    @WebMethod(operationName="Search")
    @WebResult(name = "AvailRS")
    public AvailRS search(@WebParam(name = "AvailRQ") AvailRQ request) {
        return super.search(request);
    }
}

myService.wsdl:

<?xml version='1.0' encoding='UTF-8'?>
<definitions
    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://example.com/MyService"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:ans="http://www.example.org/example"
    targetNamespace="http://example.com/MyService" name="MyService">
    <types>
        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <xsd:import schemaLocation="wsdl/xsd/AvailRQ.xsd"
                namespace="http://www.example.org/example">
            </xsd:import>
            <xsd:import schemaLocation="wsdl/xsd/AvailRS.xsd"
                namespace="http://www.example.org/example">
            </xsd:import>
        </xsd:schema>
    </types>
    <message name="SearchRequest">
        <part name="searchRequest" element="ans:AvailRQ"/>
    </message>
    <message name="SearchResponse">
        <part name="searchResponse" element="ans:AvailRS"/>
    </message>
    <portType name="MyService">
        <operation name="Search">
            <input message="tns:SearchRequest"/>
            <output message="tns:SearchResponse"/>
        </operation>
    </portType>
    <binding name="MyServicePortBinding" type="tns:MyService">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http"
            style="document" />
        <operation name="Search">
            <soap:operation soapAction="" />
            <input>
                <soap:body use="literal" />
            </input>
            <output>
                <soap:body use="literal" />
            </output>
        </operation>
    </binding>
    <service name="MyService">
        <port name="MyServicePort" binding="tns:MyServicePortBinding">
            <soap:address location="http://localhost:8080/ws/MyService" />
        </port>
    </service>
</definitions>

导入的xsd样式很好,不包含任何错误。 问题:当我向我的服务发送请求时,我总是得到AvailRQ(WebParam)== null。 我已经尝试过生成的cliend和SOAP UI。 编组/解组请求没有问题。 只是一个NullPointer :(

1 个答案:

答案 0 :(得分:0)

方法中的注释与输入消息中字段名称在WSDL中的名称之间似乎不匹配:

<portType name="MyService">
    <operation name="Search">
        <input message="tns:SearchRequest"/>
        ... 
   </operation>
</portType>
<message name="SearchRequest">
    <part name="searchRequest" element="ans:AvailRQ"/>
</message>

我会尝试查看通过网络发送的实际HTTP流量,以确定SOAP消息中的字段名称是肯定的。