2013-10-18 50 views
3

我已經實現Web服務MyWebServiceImpl,如:「javax.xml.ws.WebServiceException:是不是一個有效的服務有效的服務宗旨是:」如何解決

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

我也有喜歡

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

我想使用Soap處理程序得到響應,所以我創建了handlers.xml,LoggingHandler。然後我嘗試執行我的測試類,我得到錯誤:

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) 

回答

10

貌似serviceName參數從super(...)MyWebServiceImpl不匹配WSDL中指定的服務的名稱。看看你的WSDL文件,你應該找到下面的代碼片段:

<wsdl:service name="myWebService"> 

換上正確的服務名參數(即myWebService)。

我會推薦使用wsimport工具,而不是手工完成整個客戶端存根。它可以從命令行使用,作爲ant任務和maven插件使用。您只需指定WSDL文件或URL。這樣你可以避免繁瑣的工作。有大量的文檔,如standard Oracle manual

當然,生成的@WebServiceClient不會有@HandlerChain註解。但額外的處理程序可以在運行時輕鬆添加,例如:

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")); 
相關問題