【问题标题】:Is not a valid service exception in JAX-WS在 JAX-WS 中不是有效的服务异常
【发布时间】:2013-10-23 05:58:44
【问题描述】:

我参考http://www.mkyong.com/webservices/jax-ws/jax-ws-hello-world-example/

这是我的HelloWorldClient

package WebService;


import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;



public class HelloWorldClient{

    public static void main(String[] args) throws Exception {

    URL url = new URL("http://localhost:8099/dummy1/dummy2?wsdl");

        //1st argument service URI, refer to wsdl document above
    //2nd argument is service name, refer to wsdl document above
        QName qname = new QName("http://localhost:8099/dummy1/dummy2?wsdl", "HelloWorldImplService");


        Service service = Service.create(url, qname);

        HelloWorld hello = service.getPort(HelloWorld.class);

        System.out.println(hello.getHelloWorldAsString("mkyong"));

    }

}

运行这个类时,我从下面的代码行收到错误

Service service = Service.create(url, qname);

错误是

Exception in thread "main" javax.xml.ws.WebServiceException: {http://localhost:8099/dummy1/dummy2?wsdl}HelloWorldImplService is not a valid service. Valid services are: {http://WebService/}HelloWorldImplService
    at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:220)
    at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:165)
    at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:93)
    at javax.xml.ws.Service.<init>(Service.java:56)
    at javax.xml.ws.Service.create(Service.java:680)
    at WebService.HelloWorldClient.main(HelloWorldClient.java:19)

在 HelloWorldClient 类的参考示例中有

    QName qname = new QName("http://ws.mkyong.com/", "HelloWorldImplService");

在我的情况下,我已将其替换为

    QName qname = new QName("http://localhost:8099/dummy1/dummy2?wsdl", "HelloWorldImplService");

我无法弄清楚我在哪里犯了错误。当我跑步时 http://localhost:8099/dummy1/dummy2?wsdl 它工作正常。但是,当我从客户端访问时,我得到了上述异常。请帮忙?

【问题讨论】:

    标签: java soap jax-ws


    【解决方案1】:

    尝试替换

    QName qname = new QName("http://localhost:8099/dummy1/dummy2?wsdl", "HelloWorldImplService");
    

    QName qname = new QName("http://WebService/", "HelloWorldImplService");
    

    【讨论】:

      【解决方案2】:

      这是我解决这个问题的方法:

      1。运行 Mkyong 编写的发布者类;

      2。在浏览器中打开网址(例如:http://localhost:8099/dummy1/dummy2?wsdl);

      3。检查 WSDL 中的“targetNamespace”属性是否等于 QName 构造函数中的第一个参数。如果没有,请从 WSDL 中设置;

      4。检查 WSDL 中的“name”属性是否等于 QName 构造函数中的第二个参数。如果没有,请从 WSDL 中设置;

      5。停止客户端和发布者;

      6。运行发布者;

      7。运行客户端;

      8。享受结果 =)

      【讨论】:

        【解决方案3】:

        错误信息告诉你要修复什么:

        有效服务为:{http://WebService/}HelloWorldImplService

        对我来说,以下是必要的:

        QName qname = new QName("http://WebService/" , "HelloWorldImplService");
        

        【讨论】:

        • 谢谢!我完全错过了错误消息中的这个非常有用的信息。
        【解决方案4】:

        我没有尝试过,但我相信 QName 实例化中的第一个参数应该没有那个 ?wsdl。要求您提供命名空间,而不是 WSDL 文档的 URI。

        【讨论】:

          【解决方案5】:

          我解决了这个问题。我创建了 WebServiceClient 和 WebServices 项目。 和相同的文件: 网络服务客户端 :: webservices.HelloWorld.java webservices.HelloWorldClient.java

          WebServices :: 
          webservices.HelloWorld.java
          webservices.HelloWorldImpl.java
          webservices.HelloWorldPublisher.java
          
          I used NetBeans 8. In both project must have same name of package and 
          
          QName qname = new QName("http://webservices/", "HelloWorldImplService");
          in webservices.HelloWorldClient.java.
          The end. It runs ! Sorry My english. (Bobojonov Farruh)
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-09-15
            • 1970-01-01
            相关资源
            最近更新 更多