java - 在 JAX-WS 中定义绑定(bind)名称

标签 java web-services jax-ws

我正在开发一个 JAX-WS WebService,目前需要定义一个自定义 Binding 名称,因为它被定义为端口名称并附加了“Binding”。

例如:如果端口名称为MyJAXService,则绑定(bind)名称默认为MyJAXServiceBinding。我想要的是 Binding 名称是其他名称,例如 MyJAXService

我的 Web 服务的 @WebService 注释定义如下

@WebService(serviceName = "MyJAXService", portName = "MyJAXService", endpointInterface = "com.test.MyJAXService", targetNamespace = "http://test.local/")

最佳答案

我假设您正在使用Java 到 WSDL 方法,因此您希望从您的工件生成 WSDL。

我通常使用另一种方法,即 WSDL to Java,对于 WSDL,例如:

<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns="http://mynamespace" xmlns="http://schemas.xmlsoap.org/wsdl/"  targetNamespace="http://mynamespace">
  ...
  <portType name="MySoapBinding">
    <operation name="MyOperation">
        ...
    </operation>
  </portType>
  <binding name="MySoapBinding" type="ns:MySoapBinding">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="MyOperation">
        ...
    </operation>
  </binding>
  <service name="MyService">
    <port name="MySoapBinding" binding="ns:MySoapBinding">
      <soap:address location="http://localhost:8080/MyService"/>
    </port>
  </service>
</definitions>

生成的工件是一个接口(interface):

@WebService(name = "MySoapBinding", targetNamespace = "http://mynamespace")
public interface MySoapBinding {
    ...
}

以及实现:

@WebService(name = "MySoapBinding", targetNamespace = "http://mynamespace", endpointInterface = "my.package.MySoapBinding", serviceName = "MyService", portName = "MySoapBinding")
public class MySoapBindingImpl
    implements MySoapBinding
{
}

我想您可以尝试为 Web 服务的接口(interface)指定一个名称,生成的 WSDL 应该使用该名称作为绑定(bind)名称。

关于java - 在 JAX-WS 中定义绑定(bind)名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4749175/

相关文章:

java - 使用 Maven 为 SWT 应用程序构建多平台可执行文件

java - MongoDB - 在java中实现nor查询

c# - 如何将编码的 Web 性能测试添加到 visual studio 2012 中的负载测试

java - 无法发送 SOAP 消息

iphone - ASIHttpRequest登录身份验证问题

wsdl - 结合 JAXB 和 JAXWS 以获取导入的 XML 模式

java - Android - 以编程方式创建 View 进度条

web-services - JAX-WS Web 服务的身份验证和授权的正确方法?

java - 如何通过 CXF 中的拦截器将 SoapFault 转换为 SoapMessage?

java - 分数在计算机中是如何表示的?