【问题标题】:Metro WebService - How to Configure/Deploy?Metro WebService - 如何配置/部署?
【发布时间】:2012-05-09 20:09:18
【问题描述】:

我有一个运行良好的 Web 服务的 Metro 客户端。但是,我们在实验室环境中无法访问该服务,因此我编写了一个模拟服务进行测试。我在理解端点以及如何设置端点时遇到问题。

我将 URL 传递给客户端构造函数并在请求上下文中设置它,如下所示:

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

对于我的模拟服务,当我单击应用程序列表 (http://myserver:80/MySoapService) 中的“启动”链接时,我使用的是 Glassfish 给我的战争 URL。

代码是从提供给我们的 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>

我在设置 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"
            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 还是完全不同的东西。

谁能告诉我我做错了什么和/或向我指出一个以易于理解的方式解释这一点的资源?

【问题讨论】:

    标签: jakarta-ee deployment java-metro-framework


    【解决方案1】:

    我让它工作了,如果这对其他人有用,这是我的配置...

    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>
    

    sun-jaxws.xml

    尽管我发现许多示例/博客指出 sun-jaxws.xml 文件中的 portservice 元素是可选的,但没有它们我无法让它工作。此外,我发现如果在 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
    

    当然每个网络服务方法都需要注解WebMethod

    @WebMethod
    public String doSomething(String string)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-14
      • 2018-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      相关资源
      最近更新 更多