xugang1225 2010-10-25 16:37 采纳率: 0%
浏览 281
已采纳

webservice xfire客户端出现问题,谁帮解决下

用的是myeclipse8.0

自动生成的webservice服务器端

[color=red]1,自动生成的接口[/color]package com.test.service;
//Generated by MyEclipse

public interface IMyFirstWebS {

public String example(String message);

}

[color=red]2,实现类[/color]

package com.test.service;
//Generated by MyEclipse

public class MyFirstWebSImpl implements IMyFirstWebS {

public String example(String message) {
    return message+" My First Web Service!";

}

}
[color=red]
3,webservices/service.xml自动生成配置[/color]<?xml version="1.0" encoding="UTF-8"?>

<service>
    <name>MyFirstWebS</name>
    <serviceClass>com.test.service.IMyFirstWebS</serviceClass>
    <implementationClass>
        com.test.service.MyFirstWebSImpl
    </implementationClass>
    <style>wrapped</style>
    <use>literal</use>
    <scope>application</scope>
</service></beans>

4,发布到tomcat里访问 http://localhost:9000/WebServiceTest1/services/IMyFirstWebS?wsdl

Available Services:
MyFirstWebS [wsdl]
Generated by XFire ( http://xfire.codehaus.org )

5,建立客户端
我建立的是一个JAVA项目,但是导入了XFire 1.2 HTTP Client Libraries包
接口IMyFirstWebS.java我也复制到这个项目里了,又写了个测试类main1
import java.net.MalformedURLException;
import java.net.URL;

import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.Client;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;

public class main1 {
public static void main(String[] args) throws MalformedURLException, Exception {
Service srvcModel = new ObjectServiceFactory().create(IMyFirstWebS.class);
XFireProxyFactory factory =new XFireProxyFactory(XFireFactory.newInstance().getXFire());
String helloWorldURL = "http://localhost:9000/WebServiceTest1/services/MyFirstWebS?wsdl";
try {
IMyFirstWebS srvc = (IMyFirstWebS)factory.create(srvcModel, helloWorldURL);
String result = srvc.example("hello world");
System.out.print(result);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}
直接运行报错

Exception in thread "main" org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: There must be a method name element.
org.codehaus.xfire.fault.XFireFault: There must be a method name element.
at org.codehaus.xfire.service.binding.WrappedBinding.readMessage(WrappedBinding.java:32)
at org.codehaus.xfire.soap.handler.SoapBodyHandler.invoke(SoapBodyHandler.java:42)
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.example(Unknown Source)
at main1.main(main1.java:19)

我试过了好多种测试方法
还有这种

public class main1 {
public static void main(String[] args) throws MalformedURLException, Exception {
Client client;
client =new Client(new URL("http://localhost:9000/WebServiceTest1/services/IMyFirstWebS?WSDL"));
Object[] results=client.invoke("example", new Object[]{"hello"});
System.out.println((String)results[0]);
}
}

最后都是不对,到底哪配错了呢,服务端我访问正常,但是在java类里就是不好使,都愁死了,客户端我也建立web service client了但是也是不行

  • 写回答

1条回答

  • iteye_4873 2010-10-25 16:41
    关注

    [code="java"] String helloWorldURL = "http://localhost:9000/WebServiceTest1/services/MyFirstWebS?wsdl"; [/code]

    改成
    [code="java"]
    String helloWorldURL = "http://localhost:9000/WebServiceTest1/services/MyFirstWebS";
    [/code]

    试试~~~

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突