Java 不是 JAX-WS 中的有效服务异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19533904/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is not a valid service exception in JAX-WS
提问by abishkar bhattarai
I am taking reference from http://www.mkyong.com/webservices/jax-ws/jax-ws-hello-world-example/
我正在参考http://www.mkyong.com/webservices/jax-ws/jax-ws-hello-world-example/
This is my HelloWorldClientclass
这是我的 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"));
}
}
When running this class i am getting error from below line of code
运行这个类时,我从下面的代码行收到错误
Service service = Service.create(url, qname);
The error is
错误是
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)
In the reference example in HelloWorldClient class it has
在 HelloWorldClient 类的参考示例中,它具有
QName qname = new QName("http://ws.mkyong.com/", "HelloWorldImplService");
In my case i have replaced it with
就我而言,我已将其替换为
QName qname = new QName("http://localhost:8099/dummy1/dummy2?wsdl", "HelloWorldImplService");
I could not figure out where i have made mistake .When i run
http://localhost:8099/dummy1/dummy2?wsdl
it is working fine.But ,when i access from client i am getting above mentioned exception.Any help please ?
我不知道我在哪里犯了错误。当我运行时
http://localhost:8099/dummy1/dummy2?wsdl
它工作正常。但是,当我从客户端访问时,我遇到了上面提到的异常。请问有什么帮助吗?
回答by roxolid
I haven't tried it, but I do believe that first argument in QName instantiation should be without that ?wsdl. You are asked for providing namespace, not the URI of WSDL document.
我还没有尝试过,但我确实相信 QName 实例化中的第一个参数应该没有?wsdl。要求您提供名称空间,而不是 WSDL 文档的 URI。
回答by Paolo
Try to replace
尝试更换
QName qname = new QName("http://localhost:8099/dummy1/dummy2?wsdl", "HelloWorldImplService");
with
和
QName qname = new QName("http://WebService/", "HelloWorldImplService");
回答by Alex Henao
The error message tells you what to fix :
错误消息告诉您要修复的内容:
Valid services are: {http://WebService/}HelloWorldImplService
有效的服务是: {http://WebService/}HelloWorldImplService
for me the following was necessary:
对我来说,以下是必要的:
QName qname = new QName("http://WebService/" , "HelloWorldImplService");
回答by Aleksandr Belenov
Here is my recipe to solve this issue:
这是我解决这个问题的秘诀:
1. run the publisher class written by Mkyong;
1.运行Mkyong编写的publisher类;
2. open the url (ex: http://localhost:8099/dummy1/dummy2?wsdl) in browser;
2. 在浏览器中打开网址(例如:http://localhost:8099/dummy1/dummy2?wsdl);
3. check if "targetNamespace" property in WSDL equals to the 1st argument in QName constructor. If it doesn't, set it from WSDL;
3. 检查 WSDL 中的“targetNamespace”属性是否等于 QName 构造函数中的第一个参数。如果没有,请从 WSDL 设置它;
4. check if "name" property in WSDL equals to the 2nd argument in QName constructor. If it doesn't, set it from WSDL;
4. 检查 WSDL 中的“name”属性是否等于 QName 构造函数中的第二个参数。如果没有,请从 WSDL 设置它;
5. stop both the client and the publisher;
5. 停止客户端和发布者;
6. run the publisher;
6. 运行发布者;
7. run the client;
7.运行客户端;
8. enjoy the result =)
8.享受结果=)
回答by Bobojonov Farruh
I solved this problem. I created WebServiceClient and WebServices projects. And same files: WebServiceClient :: webservices.HelloWorld.java webservices.HelloWorldClient.java
我解决了这个问题。我创建了 WebServiceClient 和 WebServices 项目。和相同的文件: WebServiceClient :: 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)