笔者项目要用到webservice,以往都是直接用cxf或者axis,来发布和动态的生成客户端,去调用,仅仅会用。作为一个骨灰级的程序猿,笔者想一探webservice的本身,但是,出师未捷身先死,第一步,就卡主了,因为照着网上的教程,笔者碰到一个错误,而且几乎无从下手。
package server; import javax.jws.WebMethod; import javax.jws.WebService; @WebService public interface IHelloWorld { @WebMethod public String sayHello(String name); }
package server; import javax.jws.WebService; @WebService public class HelloWorldImpl implements IHelloWorld { @Override public String sayHello(String name) { return "hello [" + name + "]"; } }服务端发布类:ServerPublish
package server; import javax.xml.ws.Endpoint; public class ServerPublish { public static void main(String[] args) { Endpoint.publish("http://192.168.8.101:9001/helloworld", new HelloWorldImpl()); } }
package client.error; public class TestClient { public static void main(String[] args) { System.out.println(new HelloWorldImplService().getHelloWorldImplPort().sayHello("robin")); } }
Exception in thread "main" com.sun.xml.internal.ws.spi.db.DatabindingException: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions 两个类具有相同的 XML 类型名称 "{http://server/}sayHello"。请使用 @XmlType.name 和 @XmlType.namespace 为类分配不同的名称。 this problem is related to the following location: at client.error.SayHello at public client.error.SayHello client.error.ObjectFactory.createSayHello() at client.error.ObjectFactory this problem is related to the following location: at server.SayHello 两个类具有相同的 XML 类型名称 "{http://server/}sayHelloResponse"。请使用 @XmlType.name 和 @XmlType.namespace 为类分配不同的名称。 this problem is related to the following location: at client.error.SayHelloResponse at public client.error.SayHelloResponse client.error.ObjectFactory.createSayHelloResponse() at client.error.ObjectFactory this problem is related to the following location: at server.SayHelloResponse at com.sun.xml.internal.ws.db.glassfish.JAXBRIContextFactory.newContext(JAXBRIContextFactory.java:90) at com.sun.xml.internal.ws.spi.db.BindingContextFactory.create(BindingContextFactory.java:167) at com.sun.xml.internal.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:203) at com.sun.xml.internal.ws.model.AbstractSEIModelImpl$1.run(AbstractSEIModelImpl.java:176) at java.security.AccessController.doPrivileged(Native Method) at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:176) at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:95) at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:309) at com.sun.xml.internal.ws.db.DatabindingImpl.<init>(DatabindingImpl.java:85) at com.sun.xml.internal.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:59) at com.sun.xml.internal.ws.db.DatabindingProviderImpl.create(DatabindingProviderImpl.java:43) at com.sun.xml.internal.ws.db.DatabindingFactoryImpl.createRuntime(DatabindingFactoryImpl.java:105) at com.sun.xml.internal.ws.client.WSServiceDelegate.buildRuntimeModel(WSServiceDelegate.java:875) at com.sun.xml.internal.ws.client.WSServiceDelegate.createSEIPortInfo(WSServiceDelegate.java:892) at com.sun.xml.internal.ws.client.WSServiceDelegate.addSEI(WSServiceDelegate.java:855) at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:435) at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:404) at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:386) at javax.xml.ws.Service.getPort(Service.java:119) at client.error.HelloWorldImplService.getHelloWorldImplPort(HelloWorldImplService.java:72) at client.error.TestClient.main(TestClient.java:5) Caused by: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions 两个类具有相同的 XML 类型名称 "{http://server/}sayHello"。请使用 @XmlType.name 和 @XmlType.namespace 为类分配不同的名称。 this problem is related to the following location: at client.error.SayHello at public client.error.SayHello client.error.ObjectFactory.createSayHello() at client.error.ObjectFactory this problem is related to the following location: at server.SayHello 两个类具有相同的 XML 类型名称 "{http://server/}sayHelloResponse"。请使用 @XmlType.name 和 @XmlType.namespace 为类分配不同的名称。 this problem is related to the following location: at client.error.SayHelloResponse at public client.error.SayHelloResponse client.error.ObjectFactory.createSayHelloResponse() at client.error.ObjectFactory this problem is related to the following location: at server.SayHelloResponse at com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException$Builder.check(IllegalAnnotationsException.java:91) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:445) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:277) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:124) at com.sun.xml.internal.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1123) at com.sun.xml.internal.bind.v2.ContextFactory.createContext(ContextFactory.java:147) at com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:152) at com.sun.xml.internal.bind.api.JAXBRIContext.newInstance(JAXBRIContext.java:96) at com.sun.xml.internal.ws.developer.JAXBContextFactory$1.createJAXBContext(JAXBContextFactory.java:98) at com.sun.xml.internal.ws.db.glassfish.JAXBRIContextFactory.newContext(JAXBRIContextFactory.java:79) ... 20 more