简体   繁体   English

sun-jaxws.xml 中的 JAX-WS 多个端点

[英]JAX-WS multiple endpoints in sun-jaxws.xml

Just started using JAX-WS.刚开始使用 JAX-WS。 I created 2 test web services in the one WAR file as follows....我在一个 WAR 文件中创建了 2 个测试 web 服务,如下所示....

package com.djs;

import javax.jws.WebService;

@WebService()
public class AddTwoInts {

    public int performAdd(int firstNum, int secondNum) {
        return firstNum + secondNum;
    }
}

And.....和.....

package com.djs;

import javax.jws.WebService;

@WebService()
public class SayHello {

    public String sayHello(String inwards) {
        return "Hello " + inwards;
    }
}

This is my web.xml这是我的 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
                             http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">

    <listener>
        <listener-class>
            com.sun.xml.ws.transport.http.servlet.WSServletContextListener
        </listener-class>
    </listener>

    <servlet>
        <servlet-name>jaxws</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>jaxws</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

This is the sun-jaxws.xml这是 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='performAdd' implementation='com.djs.AddTwoInts' url-pattern='/AddTwoInts' />
    <endpoint name='sayHello' implementation='com.djs.SayHello' url-pattern='/SayHello' />
</endpoints> 


I deploy into Tomcat 7 and use http://localhost:8080/MyApp/AddTwoInts?wsdl to get the WSDL for AddTwoInts OK.... But when I execute http://localhost:8080/MyApp/SayHello?wsdl I get a 404 page not found error.... I deploy into Tomcat 7 and use http://localhost:8080/MyApp/AddTwoInts?wsdl to get the WSDL for AddTwoInts OK.... But when I execute http://localhost:8080/MyApp/SayHello?wsdl I get找不到 404 页面错误....

Any advice appreciated.任何建议表示赞赏。

Dave,戴夫,

I guess you are missing the servlet-mapping for the two end points you have.我猜你错过了你拥有的两个端点的 servlet 映射。

Add the following to your web.xml and try again.将以下内容添加到您的 web.xml 并重试。 Let me know if this solve the problem.让我知道这是否能解决问题。

<servlet>
    <servlet-name>AddTwoInts</servlet-name>
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>AddTwoInts</servlet-name>
    <url-pattern>/AddTwoInts</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>SayHello</servlet-name>
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>SayHello</servlet-name>
    <url-pattern>/SayHello</url-pattern>
</servlet-mapping>

You want the web.xml to reference only one servlet, at urlMapping /:您希望 web.xml 在 urlMapping / 处仅引用一个 servlet:

  <servlet>
    <servlet-name>services</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>services</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

Then, include multiple endpoints at the full desired path in sun-jaxws.xml:然后,在 sun-jaxws.xml 中的完整所需路径中包含多个端点:

<endpoint name='performAdd' implementation='com.djs.AddTwoInts' url-pattern='/AddTwoInts' />
<endpoint name='sayHello' implementation='com.djs.SayHello' url-pattern='/couldhavemore/SayHello' />

Note the "couldhavemore" in there... you can add to the relevant path in the sun-jaxws.xml file to get the full desired path.请注意那里的“couldhavemore”...您可以添加到 sun-jaxws.xml 文件中的相关路径以获得所需的完整路径。 I've gotten a single service to work with a web.xml entry of something other than /, but then you need a web.xml entry for every service. I've gotten a single service to work with a web.xml entry of something other than /, but then you need a web.xml entry for every service. It seems to get multiple to work you need to use / and then put the full path in sun-jaxws.xml.您需要使用 / 然后将完整路径放入 sun-jaxws.xml 中似乎需要多个工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM