2012-05-09 59 views
-1

我有一個Metro客戶端到web服務,工作正常。但是,我們無法在我們的實驗室環境中訪問該服務,因此我編寫了一個模擬測試服務。我在理解端點以及如何設置它們時遇到了問題。Metro WebService - 如何配置/部署?

我將網址傳遞到客戶機的構造和這樣的請求上下文設置它:

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

對於我的模擬服務,我使用的是戰爭的URL通過爲給我Glassfish,當我點擊應用程序列表(http:// myserver:80/MySoapService)列表中的「Launch」鏈接時。

代碼已經從提供給我們的wsdl生成。 WebService的界面看起來是這樣的:

@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"?> 
<!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> 

我無法設置我的太陽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" 
      implementation="my.package.MySoapServiceImpl" 
      url-pattern="/" 
      wsdl-location="WEB-INF/wsdl/MySoapService.wsdl"/> 
</endpoints> 

但我的客戶端找回描述服務的「Web服務」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服務實現類

我認爲有必要包括在WebSevice註釋的endpointInterface

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

當然每個Web服務方法需要與WebMethod註釋和:

@WebMethod 
public String doSomething(String string)