Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"javax.xml.ws.WebServiceException: is not a valid service. Valid services are:" how to solve

I have implemented web service MyWebServiceImpl like:

@WebServiceClient(//my parameters//)
@HandlerChain(file = "handlers.xml")
public class MyWebServiceImpl {...}

Also I have interface MyWebService like

@WebService(//my parameters//)
@XmlSeeAlso({
com.my.ObjectFactory.class,
com.my.second.ObjectFactory.class,
com.my.third.ObjectFactory.class
})
public interface MyWebService {...}

I want to get responce using Soap handler, so I have created handlers.xml, LoggingHandler. Then I try to execute my test class I get error:

javax.xml.ws.WebServiceException: {http://service.ws.my.com/}MyWebServiceImpl is not a valid service. Valid services are: {http://service.ws.my.com/}myWebService
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:223)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:168)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:96)
at javax.xml.ws.Service.<init>(Service.java:77)
at com.my.ws.service.MyWebServiceImpl.<init>(MyWebServiceImpl.java:46)
at test.MainTest.<init>(MainTest.java:354)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:187)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:236)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:233)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
like image 481
khris Avatar asked Dec 08 '22 12:12

khris


1 Answers

Looks like serviceName parameter from your super(...) in MyWebServiceImpl does not match name of the service specified in WSDL. Take a look at your WSDL file and you should find the following fragment:

<wsdl:service name="myWebService">

Replace serviceName parameter with correct one (i.e. myWebService).

I would recommend using wsimport tool instead of implementing by hand whole client stub. It can be used from command line, as an ant task and as a maven plugin. You just need to specify WSDL file or URL. This way you can avoid tedious work. There is plenty of documentation, like standard Oracle manual.

Of course generated @WebServiceClient won't have @HandlerChain annotation. But additional handlers can be easily added at runtime, e.g.:

MyWebServiceImplService service = new MyWebServiceImplService();
MyWebService myWebService = service.getMyWebServiceImplPort();
List<Handler> handlerChain = new ArrayList<Handler>();
handlerChain.add(new LoggingHandler());
((BindingProvider) myWebService).getBinding().setHandlerChain(
        handlerChain);

System.out.println(myWebService.hello("world"));
like image 72
Dawid Pytel Avatar answered Dec 27 '22 10:12

Dawid Pytel