Red Hat Training

A Red Hat training course is available for Red Hat JBoss Enterprise Application Platform

16.6. JAX-WS 開発リファレンス

16.6.1. Web サービスアドレス指定を有効にする (WS-Addressing)

前提条件

  • アプリケーションに既存の JAX-WS サービスおよびクライアント設定を指定する必要があります。

手順16.2 クライアントコードに注釈を付けて更新する

  1. サービスエンドポイントに注釈を付ける

    追加します@Addressingアプリケーションのエンドポイントコードへの注釈。

    例16.28 @Addressing Annotation

    この例は、通常の JAX-WS エンドポイントを示しています。@Addressing注釈が追加されました。
    package org.jboss.test.ws.jaxws.samples.wsa;
     
    import javax.jws.WebService;
    import javax.xml.ws.soap.Addressing;
     
    @WebService
    (
       portName = "AddressingServicePort",
       serviceName = "AddressingService",
       wsdlLocation = "WEB-INF/wsdl/AddressingService.wsdl",
       targetNamespace = "http://www.jboss.org/jbossws/ws-extensions/wsaddressing",
       endpointInterface = "org.jboss.test.ws.jaxws.samples.wsa.ServiceIface"
    )
    @Addressing(enabled=true, required=true)
    public class ServiceImpl implements ServiceIface
    {
       public String sayHello()
       {
          return "Hello World!";
       }
    }
  2. クライアントコードを更新する

    アプリケーションのクライアントコードを更新して、WS-Addressing を設定します。

    例16.29 WS-Addressing のクライアント設定

    この例は、WS-Addressing を設定するために更新された通常の JAX-WS クライアントを示しています。
    package org.jboss.test.ws.jaxws.samples.wsa;
     
    import java.net.URL;
    import javax.xml.namespace.QName;
    import javax.xml.ws.Service;
    import javax.xml.ws.soap.AddressingFeature;
     
    public final class AddressingTestCase
    {
       private final String serviceURL = 
           "http://localhost:8080/jaxws-samples-wsa/AddressingService";
       
       public static void main(String[] args) throws Exception
       {
          // construct proxy
          QName serviceName = 
              new QName("http://www.jboss.org/jbossws/ws-extensions/wsaddressing",
                        "AddressingService");
          URL wsdlURL = new URL(serviceURL + "?wsdl");
          Service service = Service.create(wsdlURL, serviceName);
          ServiceIface proxy = 
              (ServiceIface)service.getPort(ServiceIface.class,  
                                            new AddressingFeature());
          // invoke method
          proxy.sayHello();
       }
    }

結果

クライアントとエンドポイントは、WS-Addressing を使用して通信しています。