2012-05-09 21 views
-1

私は正常に動作するWebサービスへのMetroクライアントを持っています。しかし、私たちのラボ環境ではサービスにアクセスすることができないので、私はテストのための模擬サービスを書いていました。私はエンドポイントを理解し、それらを設定する方法に問題があります。メトロWebService - 設定/配備の方法?

私はクライアントのコンストラクタにURLを渡すと、このような要求コンテキストでそれを設定しています:私のモックサービスについては

// Set the service port URL 
    BindingProvider bindingProvider = ((BindingProvider) port); 
    Map<String, Object> context = bindingProvider.getRequestContext(); 
    context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serviceURL); 

、私に与えられて、私は戦争のURLを使用しています(http:// myserver:80/MySoapService)のリストで "Launch"リンクをクリックするとGlassfishが表示されます。

コードは、私たちに提供されたwsdlから生成されています。 Webサービスのインタフェースは、このようなものになります。私は私の日-jaxws.xmlファイルの設定、トラブルを抱えている

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd"> 

<web-app> 
    <listener> 
     <listener-class> 
      com.sun.xml.ws.transport.http.servlet.WSServletContextListener </listener-class> 
    </listener> 
    <servlet> 
     <servlet-name>MySoapService</servlet-name> 
     <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>MySoapService</servlet-name> 
     <url-pattern>/*</url-pattern> 
    </servlet-mapping> 
    <session-config> 
     <session-timeout>60</session-timeout> 
    </session-config> 
</web-app> 

@WebService(name = "My_Soap_Service", targetNamespace = "urn:My.DataEntityModel") 
@XmlSeeAlso({ 
    ObjectFactory.class 
}) 
public interface MySoapService { 


    @WebMethod(operationName = "Ping", action = "urn:My.DataEntityModel/Ping") 
    @WebResult(name = "PingResult", targetNamespace = "urn:My.DataEntityModel") 
    @RequestWrapper(localName = "Ping", targetNamespace = "urn:My.DataEntityModel", className = "dataentitymodel.Ping") 
    @ResponseWrapper(localName = "PingResponse", targetNamespace = "urn:My.DataEntityModel", className = "dataentitymodel.PingResponse") 
    public String ping(
     @WebParam(name = "inputString", targetNamespace = "urn:My.DataEntityModel") 
     String inputString); 


    @WebMethod(operationName = "ProcessRecordResult", action = "urn:My.DataEntityModel/ProcessRecordResult") 
    @WebResult(name = "ProcessRecordResultResult", targetNamespace = "urn:My.DataEntityModel") 
    @RequestWrapper(localName = "ProcessRecordResult", targetNamespace = "urn:My.DataEntityModel", className = "dataentitymodel.ProcessRecordResult") 
    @ResponseWrapper(localName = "ProcessRecordResultResponse", targetNamespace = "urn:My.DataEntityModel", className = "dataentitymodel.ProcessRecordResultResponse") 
    public String ProcessRecordResult(
     @WebParam(name = "recordStatusXML", targetNamespace = "urn:My.DataEntityModel") 
     String recordStatusXML); 


    @WebMethod(operationName = "ProcessBatchResult", action = "urn:My.DataEntityModel/ProcessBatchResult") 
    @WebResult(name = "ProcessBatchResultResult", targetNamespace = "urn:My.DataEntityModel") 
    @RequestWrapper(localName = "ProcessBatchResult", targetNamespace = "urn:My.DataEntityModel", className = "dataentitymodel.ProcessBatchResult") 
    @ResponseWrapper(localName = "ProcessBatchResultResponse", targetNamespace = "urn:My.DataEntityModel", className = "dataentitymodel.ProcessBatchResultResponse") 
    public String processBatchResult(
     @WebParam(name = "batchStatusXML", targetNamespace = "urn:My.DataEntityModel") 
     String batchStatusXML); 

} 

を私のweb.xmlは次のようになります。最初は次のようになりました:

<?xml version="1.0" encoding="UTF-8"?> 
<endpoints 
     xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" 
     version="2.0"> 
    <endpoint 
      name="MyService" 
      implementation="my.package.MySoapServiceImpl" 
      url-pattern="/" 
      wsdl-location="WEB-INF/wsdl/MySoapService.wsdl"/> 
</endpoints> 

しかし、私のクライアントはサービスを記述した「Web Services」HTMLページを入手しました。私はsun-jaxws.xmlファイルの実用的な情報や例を見つけることができませんでしたが、私はWebサービスの各メソッドのエンドポイントが必要であると考えました。そこで、次のように変更しました。

<?xml version="1.0" encoding="UTF-8"?> 
<endpoints 
     xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" 
     version="2.0"> 
    <endpoint 
      name="Ping" 
      implementation="my.package.MySoapServiceImpl" 
      url-pattern="/ping" 
      wsdl-location="WEB-INF/wsdl/MySoapService.wsdl"/> 

    <endpoint 
      name="ProcessRecord" 
      implementation="my.package.MySoapServiceImpl" 
      url-pattern="/processRecordResult" 
      wsdl-location="WEB-INF/wsdl/MySoapService.wsdl"/> 

    <endpoint 
      name="ProcessBatch" 
      implementation="my.package.MySoapServiceImpl" 
      url-pattern="/processBatchResult" 
      wsdl-location="WEB-INF/wsdl/MySoapService.wsdl"/> 

</endpoints> 

クライアントがサービスにアクセスしようとすると、404エラーが表示されるようになりました。

私はsun-jaxws.xmlおよび/またはweb.xmlファイルを間違って設定しているのか、クライアントで間違ったURLを使用しているのか、全く異なるものを使用しているのか分かりません。

誰かが私が間違っていることを教えてもらえますか、それとも分かりやすい方法でこれを説明するリソースを指摘できますか?

答えて

0

が、私はそれが動作し、ケースには、これは他の人に役立ちました、ここに私の設定...

web.xmlの

<web-app> 
    <listener> 
     <listener-class> 
      com.sun.xml.ws.transport.http.servlet.WSServletContextListener </listener-class> 
    </listener> 
    <servlet> 
     <servlet-name>MySoapService</servlet-name> 
     <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>MySoapService</servlet-name> 
     <url-pattern>/service</url-pattern> 
    </servlet-mapping> 
    <session-config> 
     <session-timeout>60</session-timeout> 
    </session-config> 
</web-app> 

日、jaxws.xmlです

私は多くの例/ブログを見つけましたがportserviceの要素はsun-jaxws.xmlファイルに含まれていますが、これらの要素がなくても動作させることはできませんでした。また、Glassfishにデプロイする場合、sun-jaxws.xmlファイル自体はオプションであると書いてあります。しかし、再び私はそれが義務的であると感じました。

<?xml version="1.0" encoding="UTF-8"?> 
<endpoints 
     xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" 
     version="2.0"> 
    <endpoint 
     name="MyService" 
     interface="my.package.MySoapServiceInterface" 
     implementation="my.package.MySoapServiceImpl" 
     service="{urn:my.xmlns.tns.urn}My_Soap_Service" 
     port="{urn:my.xmlns.tns.urn}My_Port_Type" 
     url-pattern="/service" 
     wsdl="WEB-INF/wsdl/MyService.wsdl" 
</endpoints> 

WebサービスのImplクラス

私はWebSevice注釈でendpointInterfaceを含めることが必要見つかりました

@WebService(endpointInterface="my.package.MySoapServiceInterface") 
public class MySoapServiceImpl implements MySoapServiceInterface 

と当然の各WebサービスメソッドがWebMethodでアノテートする必要があります:

@WebMethod 
public String doSomething(String string) 
関連する問題