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]

    试试~~~

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

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境