求助CXF写HelloWorld 的例子

pengtaiwei 2010-01-27 02:38:05
按照CXF官方网站的步骤,可Client调用的时候确出现
javax.xml.ws.WebServiceException: Could not find operation info for web method sayHi.
的异常.大家帮我看看,很着急,多谢多谢!

接口HelloWorld 代码如下:

package com.lbg.ws.test
import javax.jws.WebService;
@WebService(name="HelloWorld")
public interface HelloWorld {
@WebMethod(operationName="sayHi")
String sayHi(String text);
}

实现类HelloWorldImpl 代码如下:

package com.lbg.ws.test
@WebService(endpointInterface="com.lbg.ws.test.IHelloWorld")
public class HelloWorldImpl implements HelloWorld {
public String sayHi(String text) {
return "Hello " + text;
}
}

beans.xml如下:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
<import resource="classpath:META-INF/cxf/cxf-extension-javascript-client.xml"/>

<bean id="helloWorldImpl" class="com.lbg.ws.test.impl.HelloWorld"/>
<jaxws:endpoint id="helloWorld" implementor="#helloWorldImpl"
address="/HelloWorld"/>


Web.xml 的配置
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>

client的xml如下:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schema/jaxws.xsd">

<bean id="client" class="com.tjsoft.HelloWorld"
factory-bean="clientFactory" factory-method="create" />

<bean id="clientFactory"
class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="com.tjsoft.HelloWorld" />
<property name="address" value="http://192.9.207.230:8080/dzmd/services/HelloWorld" />
</bean>

Client调用代码如下:

package com.tjsoft;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public final class ClientServer{
private ClientServer(){

}
public static void main(String args[]) throws Exception{

String str="WebRoot/WEB-INF/applicationContext.xml";

ApplicationContext context = new FileSystemXmlApplicationContext(str);

HelloWorld client = (HelloWorld) context.getBean("client");

String response = client.sayHello("邓建利");

System.out.println("结果: " + response);

System.exit(0);
}

}


访问http://192.9.207.230:8080/dzmd/services/HelloWorld?wsdl内容也可以显示

...全文
68 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengtaiwei 2010-01-27
  • 打赏
  • 举报
回复
请教各位大侠如何解决???????????
解决的给你们加分。
pengtaiwei 2010-01-27
  • 打赏
  • 举报
回复
上面有一个地方写错了,就是客户端调用的时候是

String response = client.sayHi( "邓建利 ");

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧