2017-06-06 360 views
0

我想在創建Web服務時設置空目標名稱空間。這裏是例子。我的服務是這樣的:如何在Web服務中配置空的targetNamespace?

package com.example; 

import javax.jws.WebMethod; 
import javax.jws.WebService; 

@WebService 
public class SampleService 
{ 
    @WebMethod 
    public void sampleMethod() 
    { 

    } 
} 

定義的那樣,它接受看起來像這樣的請求(請注意考試命名空間聲明):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:exam="http://example.com/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <exam:sampleMethod/> 
    </soapenv:Body> 
</soapenv:Envelope> 

我想配置Web服務接受看起來像這樣的請求(沒有命名空間):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <sampleMethod/> 
    </soapenv:Body> 
</soapenv:Envelope> 

我試圖將targetNamespace設置爲空的stri ng,但這並不奏效 - 它只是默認爲考試命名空間。

@WebService(targetNamespace="")

我使用Apache CXF(3.1.0),以公開服務:

<bean id="sampleService" class="com.example.SampleService" /> 
<jaxws:endpoint id="sampleServiceWs" implementor="#sampleService" 
    address="/SampleService" publish="true"> 
</jaxws:endpoint> 

回答

0

回答我的問題 - 我沒有找到一種方法來設置空的targetNamespace,但是我設法忽略了對我的服務的請求驗證,所以它現在也接受帶有命名空間的請求。爲此,我在服務等級上使用了@EndpointProperty註釋:

package com.example; 

import javax.jws.WebMethod; 
import javax.jws.WebService; 
import org.apache.cxf.annotations.EndpointProperty; 

@WebService 
@EndpointProperty(key = "soap.no.validate.parts", value = "true") 
public class SampleService 
{ 
    @WebMethod 
    public void sampleMethod() 
    { 

    } 
}