Java 在JAX-WS中不是有效的服务异常
我正在参考 这是我的HelloWorldClient课程Java 在JAX-WS中不是有效的服务异常,java,soap,jax-ws,Java,Soap,Jax Ws,我正在参考 这是我的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
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)
就我而言,我已将其替换为
QName qname = new QName("http://localhost:8099/dummy1/dummy2?wsdl", "HelloWorldImplService");
当我跑的时候,我想不出我犯了什么错误
http://localhost:8099/dummy1/dummy2?wsdl
它工作正常。但是,当我从客户端访问时,我遇到了上面提到的异常。有什么帮助吗?我还没有尝试过,但我相信QName实例化中的第一个参数应该没有wsdl。要求您提供名称空间,而不是WSDL文档的URI。尝试替换
QName qname = new QName("http://localhost:8099/dummy1/dummy2?wsdl", "HelloWorldImplService");
与
错误消息告诉您要修复的内容: 有效服务包括:
{http://WebService/}HelloWorldImplService
对我来说,以下是必要的:
QName qname = new QName("http://WebService/" , "HelloWorldImplService");
以下是我解决这个问题的方法: 一,。运行Mkyong编写的publisher类 二,。打开url(例如:http://localhost:8099/dummy1/dummy2?wsdl)在浏览器中 三,。检查WSDL中的“targetNamespace”属性是否等于QName构造函数中的第一个参数。如果没有,则从WSDL设置它 四,。检查WSDL中的“name”属性是否等于QName构造函数中的第二个参数。如果没有,则从WSDL设置它 五,。停止客户端和发布服务器 六,。管理出版商 七,。运行客户端
八,。享受结果=)我解决了这个问题。我创建了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)
谢谢我在错误消息中完全错过了这个非常有用的信息。
QName qname = new QName("http://WebService/" , "HelloWorldImplService");
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)