我正在开发一个 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/