2012-05-09 3 views
-1

webservice에 Metro 클라이언트가있어 제대로 작동합니다. 그러나 랩 환경에서는 서비스에 액세스 할 수 없으므로 테스트 용 모의 서비스를 작성했습니다. 엔드 포인트를 이해하고이를 설정하는 방법에 문제가 있습니다.메트로 웹 서비스 - 구성/배포 방법

나는 클라이언트 생성자에 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) 응용 프로그램 목록에서 "시작"링크를 클릭하면 Glassfish가 나타납니다.

코드는 우리에게 제공되는 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> 

을하지만 내 클라이언트는 서비스를 다시 설명 된 "웹 서비스"HTML 페이지를 가지고 : 처음에는이처럼 보였다. 실용 정보/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="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 오류가 발생합니다.

클라이언트에서 잘못된 URL을 사용하거나 완전히 다른 것을 사용하여 sun-jaxws.xml 및/또는 web.xml 파일을 잘못 설정하는지 잘 모릅니다.

누군가 내가 잘못하고있는 것을 말해 줄 수 있습니까? 그리고/또는 쉽게 설명 할 수있는 방법을 설명하는 리소스를 가르쳐 주시겠습니까?

답변

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> 

웹 서비스 IMPL 클래스

나는 그것이 필요한 WebSevice 주석의 endpointInterface를 포함 발견

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

각 웹 서비스 방법은 WebMethod 주석에 필요 물론

:

@WebMethod 
public String doSomething(String string)