2014-02-21 53 views
0

接口:JAX-WS不能從操作PARAMS與默認命名空間

@WebService 
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.ENCODED, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED) 
public interface WebServ { 

    @WebMethod(action = "Sum", operationName = "Sum") 
    public abstract String sum(@WebParam(name = "a") int a, @WebParam(name = "b") int b); 

} 

實現:

@WebService(endpointInterface = "com.company.wstest.WebServ") 
public class WebServImpl implements WebServ { 
    @Override 
    public String sum(@WebParam(name = "a") int a, @WebParam(name = "b") int b) { 
     return String.valueOf(a + b); 
    } 
} 

發佈:

String endPoint = "http://localhost:" + port + "/" + env; 
Endpoint endpoint = Endpoint.publish(endPoint, new WebServImpl()); 
if (endpoint.isPublished()) { 
    System.out.println("Web service published for '" + env + "' environment"); 
    System.out.println("Web service url: " + endPoint); 
    System.out.println("Web service wsdl: " + endPoint + "?wsdl"); 
} 

如果我從了SoapUI這樣的要求(這是自動從WSDL生成)發送:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wst="http://wstest.company.com/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <wst:Sum> 
     <a>6</a> 
     <b>7</b> 
     </wst:Sum> 
    </soapenv:Body> 
</soapenv:Envelope> 

我得到正確的答案:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> 
    <S:Body> 
     <ns2:SumResponse xmlns:ns2="http://wstest.company.com/"> 
     <return>13</return> 
     </ns2:SumResponse> 
    </S:Body> 
</S:Envelope> 

但我真正需要的,這是送與默認的請求命名空間:

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> 
    <Header/> 
    <Body> 
     <Sum xmlns="http://wstest.company.com/"> 
     <a>6</a> 
     <b>7</b> 
     </Sum> 
    </Body> 
</Envelope> 

和響應是:

... 
<return>0</return> 
... 

我怎麼理解這個參數(a和b)爲空......這很奇怪,因爲jax-ws解析請求沒有錯誤。它看到操作,但不參數。做一個人知道什麼是問題?

回答

1

原因:「a」和「b」從其父「Sum」繼承命名空間「http://wstest.company.com/」。

解決方案:擺列@WebService和@WebParam相同的目標(使用相同的默認命名空間爲 「A」, 「B」 和 「點心」):

@WebService(endpointInterface = "com.company.wstest.WebServ", targetNamespace = "http://wstest.company.com/") 
public class WebServImpl implements WebServ { 
    @Override 
    public String sum(@WebParam(name = "a", targetNamespace = "http://wstest.company.com/") int a 
        ,@WebParam(name = "b", targetNamespace = "http://wstest.company.com/") int b) { 
     return String.valueOf(a + b); 
    } 
}