如何在 Web 服务中配置空的 targetNamespace?

How to configure empty targetNamespace in the Web Service?

我试图在创建 Web 服务时设置空的目标命名空间。这是例子。我的服务如下所示:

package com.example;

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

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

    }
}

这样定义的,它接受看起来像这样的请求(请注意 exam 命名空间声明):

<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 设置为空字符串,但这没有用 - 它只是默认为 exam 命名空间。

@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>

回答我的问题 - 我没有找到设置空 targetNamespace 的方法,但我设法在我的服务上省略了请求验证,因此它现在也接受带有命名空间的请求。为此,我在服务 class:

之上使用了 @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()
    {

    }
}