我是 Web 服务的新手,我开发了一个 Web 服务并将其发布在我的本地主机上,以在单独的 maven 项目中调用 Web 服务内的方法。我正在使用下面的代码来调用调用:
String targetNamespace = "http://Webservice.Rahul.com/";
QName serviceName = new QName(targetNamespace,"CallWebserviceImplService");
//portName - Qualified name for the target service endpoint
QName portName = new QName(targetNamespace,"CallWebService");
//operationName - Qualified Name of the operation for which the Call object is to be created.
QName operationName = new QName("add");
// Specify the location of the WSDL file
URL wsdlDocumentLocation = (on local host)
// Create an instance of service factory
ServiceFactory serviceFactory = ServiceFactory.newInstance();
//Create a service object to act as a factory for proxies.
Service service = serviceFactory.createService(wsdlDocumentLocation, serviceName);
Call call = (Call) service.createCall(portName);
call.setProperty("javax.xml.rpc.soap.operation.style","rpc");
String name=(String) call.invoke(operationName, null);
但这给了我以下例外:
-------------------------------------------------------------------------------
Test set: com.xaptum.router.SendSmsTest
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 63.994 sec <<< FAILURE!
main(com.xaptum.router.SendSmsTest) Time elapsed: 63.947 sec <<< ERROR!
operation style: "rpc" not supported
at com.sun.xml.rpc.client.dii.BasicCall.unsupportedOperationStyleException(BasicCall.java:583)
at com.sun.xml.rpc.client.dii.BasicCall.invoke(BasicCall.java:515)
at com.sun.xml.rpc.client.dii.BasicCall.invoke(BasicCall.java:541)
at com.xaptum.commandrouter.DMService.DMService.PushConnector(DMService.java:173)
at com.xaptum.commandrouter.DMService.DMService.callRouteHandler(DMService.java:73)
at com.xaptum.router.SendSmsTest.main(SendSmsTest.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
un.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at eflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at en.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at ven.sur
为什么我会收到此错误?任何帮助深表感谢。
网络服务代码如下:
@WebService(endpointInterface="com.Rahul.Webservice.CallWebService")
@SOAPBinding(style=Style.RPC)
public class CallWebserviceImpl implements CallWebService{
@Override
@WebMethod
public String add();
}