【问题标题】:How to configure empty targetNamespace in the Web Service?如何在 Web Service 中配置空的 targetNamespace?
【发布时间】:2017-06-06 09:20:52
【问题描述】:

我试图在创建 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>

【问题讨论】:

    标签: web-services java-8 cxf jax-ws javax


    【解决方案1】:

    回答我的问题 - 我没有找到设置空 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()
        {
    
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-09-09
      • 2016-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-25
      • 1970-01-01
      • 1970-01-01
      • 2018-01-23
      相关资源
      最近更新 更多