比较急,麻烦帮忙看看。谢谢!
自己写了个xfire+java的webservice,部署成功,在服务器端访问http://localhost:8000/test/service/UserService?wsdl
成功显示:
 <?xml version="1.0" encoding="UTF-8" ?>  
- <wsdl:definitions targetNamespace="http://webservice.test.com.cn" xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:tns="http://webservice.test.com.cn" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
- <wsdl:types>
- <xsd:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://webservice.test.com.cn" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
.........但是写了个客户端调用http://localhost:8000/test/service/UserService报错:
Exception in thread "main" org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: Invalid operation: {http://client}info
org.codehaus.xfire.fault.XFireFault: Invalid operation: {http://client}info
at org.codehaus.xfire.fault.Soap11FaultSerializer.readMessage(Soap11FaultSerializer.java:31)
at org.codehaus.xfire.fault.SoapFaultSerializer.readMessage(SoapFaultSerializer.java:28)
at org.codehaus.xfire.soap.handler.ReadHeadersHandler.checkForFault(ReadHeadersHandler.java:111)
at org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:67)
at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.client.Client.onReceive(Client.java:406)
at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:139)
at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)
at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)
at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:79)
at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:114)
at org.codehaus.xfire.client.Client.invoke(Client.java:336)
at org.codehaus.xfire.client.XFireProxy.handleRequest(XFireProxy.java:77)
at org.codehaus.xfire.client.XFireProxy.invoke(XFireProxy.java:57)
at $Proxy0.info(Unknown Source)
at client.ClientTest.main(ClientTest.java:41)
客户端代码:
public static void main(String[] args) {
String name = "20090908";
Service srModel = new ObjectServiceFactory().create(TestService.class);
XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
.newInstance().getXFire());
String serviceURL = "http://localhost:8000/test/service/UserService";
try {
TestService service = (TestService) factory.create(srModel,
serviceURL);
org.codehaus.xfire.client.XFireProxy proxy = (XFireProxy) Proxy
.getInvocationHandler(service);
org.codehaus.xfire.client.Client client = proxy.getClient();
HttpClientParams params = new HttpClientParams();
params.setParameter(HttpClientParams.USE_EXPECT_CONTINUE,
Boolean.FALSE);
Long time = 100L;
params.setParameter(HttpClientParams.CONNECTION_MANAGER_TIMEOUT,
time);
client.setProperty(CommonsHttpMessageSender.HTTP_CLIENT_PARAMS,
params);  
 String infos = service.info(name);
 System.out.println(infos);
} catch (MalformedURLException e) {
e.printStackTrace();
} }

解决方案 »

  1.   

    Exception in thread "main" org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested 不能连接远程服务, 客户端是根据服务端的WSDL生成的, 生成后的类有一个名为xxxxClient , 里边有main方法,你在那执行试试。
      

  2.   

    我刚开始弄webservice,不太明白你的意思。那个调用服务端的方法是我自己写的。
    你说的生成的xxxxClient,在哪里呢?
      

  3.   

    用另外的方法解决了,谢谢。
    public static void main(String[] args) throws ServiceException,
    MalformedURLException, RemoteException {
    String endpoint = "http://localhost:8000/test/service/UserService";
    org.apache.axis.client.Service service = new org.apache.axis.client.Service();
    org.apache.axis.client.Call call = (org.apache.axis.client.Call) service.createCal();
    call.setTargetEndpointAddress(new java.net.URL(endpoint));
    call.setOperationName("userInfoToXml");
    call.addParameter("name",org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
    call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
    call.setUseSOAPAction(true);
    String name = "username";
    String res = (String) call.invoke(new Object[] {name});
    System.out.print(res);
    }