Define binding name in JAX-WS

2019-07-21 07:24发布

问题:

I'm developing a JAX-WS WebService and I currently need to define a custom Binding name, since it gets defined as the Port name with "Binding" appended to it.

E.g.: If the Port name is MyJAXService the Binding name is going to be MyJAXServiceBinding by default. What I wanted was for the Binding name to be something else like MyJAXService.

My web service has the @WebService annotation defined as follows

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

回答1:

I suppose that you are using the Java to WSDL approach so, you want to generate the WSDL from your artifacts.

I usually use the other approach, WSDL to Java and, for a WSDL like:

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

The artifacts generated are, an interface:

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

and the implementation:

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

I guess that you can try to give a name to the interface of the web service and the WSDL generated should use that name as the Binding name.



回答2:

Make a WDSL you like, run wsdl2java, see which sn@ils are turn up on the generated code, use them.