Reputation: 7651
I am taking reference from http://www.mkyong.com/webservices/jax-ws/jax-ws-hello-world-example/
This is my HelloWorldClient class
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
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 ?
Upvotes: 4
Views: 15340
Reputation: 1
I solved this problem. I created WebServiceClient and WebServices projects. And same files: 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)
Upvotes: 0
Reputation: 31
The error message tells you what to fix :
Valid services are: {http://WebService/}HelloWorldImplService
for me the following was necessary:
QName qname = new QName("http://WebService/" , "HelloWorldImplService");
Upvotes: 1
Reputation: 412
Here is my recipe to solve this issue:
1. run the publisher class written by Mkyong;
2. open the url (ex: http://localhost:8099/dummy1/dummy2?wsdl) in browser;
3. check if "targetNamespace" property in WSDL equals to the 1st argument in QName constructor. If it doesn't, set it from WSDL;
4. check if "name" property in WSDL equals to the 2nd argument in QName constructor. If it doesn't, set it from WSDL;
5. stop both the client and the publisher;
6. run the publisher;
7. run the client;
8. enjoy the result =)
Upvotes: 3
Reputation: 1691
Try to replace
QName qname = new QName("http://localhost:8099/dummy1/dummy2?wsdl", "HelloWorldImplService");
with
QName qname = new QName("http://WebService/", "HelloWorldImplService");
Upvotes: 6
Reputation: 135
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.
Upvotes: 0