CXF的第一个hello_world_code_first例子

8 views
Skip to first unread message

cxf-zh

unread,
Aug 31, 2007, 12:42:58 AM8/31/07
to cxf-zh, Could
我开始是看了代码自己写总是出现错误,然后我下载了这个例子,并且把它复制到eclipse下面运行,我没有攺任何代码。

产生的wsdl是
<?xml version="1.0" encoding="utf-8" ?>
- <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:ns1="http://server.hw.demo/" xmlns:ns2="http://
schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/
wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
name="HelloWorld" targetNamespace="http://server.hw.demo/">
- <wsdl:types>
- <xsd:schema xmlns="http://server.hw.demo/"
attributeFormDefault="unqualified" elementFormDefault="unqualified"
targetNamespace="http://server.hw.demo/" xmlns:xsd="http://www.w3.org/
2001/XMLSchema">
<xsd:element name="sayHi" type="sayHi" />
- <xsd:complexType name="sayHi">
- <xsd:sequence>
<xsd:element minOccurs="0" name="arg0" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="sayHiResponse" type="sayHiResponse" />
- <xsd:complexType name="sayHiResponse">
- <xsd:sequence>
<xsd:element minOccurs="0" name="return" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
- <wsdl:message name="sayHi">
<wsdl:part element="ns1:sayHi" name="parameters" />
</wsdl:message>
- <wsdl:message name="sayHiResponse">
<wsdl:part element="ns1:sayHiResponse" name="parameters" />
</wsdl:message>
- <wsdl:portType name="HelloWorld">
- <wsdl:operation name="sayHi">
<wsdl:input message="ns1:sayHi" name="sayHi" />
<wsdl:output message="ns1:sayHiResponse" name="sayHiResponse" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="HelloWorldSoapBinding" type="ns1:HelloWorld">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/
soap/http" />
- <wsdl:operation name="sayHi">
<soap:operation soapAction="" style="document" />
- <wsdl:input name="sayHi">
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output name="sayHiResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="HelloWorld">
- <wsdl:port binding="ns1:HelloWorldSoapBinding"
name="HelloWorldImplPort">
<soap:address location="http://localhost:9000/helloWorld" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
但是一运行就出现这个错误。
信息: Interceptor has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not send Message.
at
org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:
48)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:
206)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:253)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:204)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:
73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:
134)
at $Proxy12.sayHi(Unknown Source)
at demo.hw.client.Client.main(Client.java:48)
Caused by: java.net.MalformedURLException
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at org.apache.cxf.transport.http.HTTPConduit.getURL(HTTPConduit.java:
703)
at org.apache.cxf.transport.http.HTTPConduit.getURL(HTTPConduit.java:
693)
at
org.apache.cxf.transport.http.HTTPConduit.setupURL(HTTPConduit.java:
632)
at org.apache.cxf.transport.http.HTTPConduit.prepare(HTTPConduit.java:
461)
at
org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:
46)
... 7 more
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Could
not send Message.
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:
168)
at $Proxy12.sayHi(Unknown Source)
at demo.hw.client.Client.main(Client.java:48)
Caused by: org.apache.cxf.interceptor.Fault: Could not send Message.
at
org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:
48)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:
206)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:253)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:204)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:
73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:
134)
... 2 more
Caused by: java.net.MalformedURLException
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at org.apache.cxf.transport.http.HTTPConduit.getURL(HTTPConduit.java:
703)
at org.apache.cxf.transport.http.HTTPConduit.getURL(HTTPConduit.java:
693)
at
org.apache.cxf.transport.http.HTTPConduit.setupURL(HTTPConduit.java:
632)
at org.apache.cxf.transport.http.HTTPConduit.prepare(HTTPConduit.java:
461)
at
org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:
46)
... 7 more
为什么呀。请教各們高手指点下呀。我是弄了两天了,还没有找到问题所在呀

willem

unread,
Aug 31, 2007, 1:50:27 AM8/31/07
to cxf-zh

请参考
http://groups.google.com/group/cxf-zh/msg/0078f1a851f4da8d

你客户端的代码没有贴出来, 不过我猜问题都差不多。

还有就是建议你先从CXF的wsdl first的例子开始学习,code frist缺省要处理的东西很多。

cxf-zh

unread,
Aug 31, 2007, 3:08:43 AM8/31/07
to cxf-zh

我直接在CMD下面调用ant build,ant server,ant client却是没有错的。并且输出Hello World!来,但是我
把这些代码放到eclipse下面运行却出现错误了。发布后我能看到wsdl,但是客户端调用总是出错。
客户端的代码如下:我一点都没有攺动它。

package demo.hw.client;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;

import demo.hw.server.HelloWorld;

public final class Client {

private static final QName SERVICE_NAME
= new QName("http://server.hw.demo/", "HelloWorld");
private static final QName PORT_NAME
= new QName("http://server.hw.demo/", "HelloWorldPort");


private Client() {
}

public static void main(String args[]) throws Exception {
Service service = Service.create(SERVICE_NAME);
// Endpoint Address
String endpointAddress = "http://localhost:9000/helloWorld";

// Add a port to the Service
service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING,
endpointAddress);

HelloWorld hw = service.getPort(HelloWorld.class);
System.out.println(hw.sayHi("World"));

}

}

Willem Jiang

unread,
Aug 31, 2007, 3:19:36 AM8/31/07
to cxf...@googlegroups.com
你在Eclipse中使用的CXF版本是什么。
单从代码上看没有看出什么问题

cxf-zh

unread,
Aug 31, 2007, 3:41:26 AM8/31/07
to cxf-zh

我用的包是2.0的,我就是建立一个JAVA工程,然后添加外置包,就是CXF2.0 lib下面的包。非常喜欢这个讨论组,我在上海怎么都没有发现在
用webservice的人呀。都不多呀。汗。。。。。。。。。。。。。。不知什么原因。上面的那个兄弟,我可以加你的MSN吗。我的是
yunj...@hotmail.com,想向你学习。

willem

unread,
Aug 31, 2007, 5:05:51 AM8/31/07
to cxf-zh
建议你使用CXF2.0.1 以后的版本。
其实你用的hello_world_code_first 是在2.0.1以后才加入到代码库的。
2.0.1 修复很多2.0的补丁。


On Aug 31, 3:41 pm, cxf-zh <yunjit...@gmail.com> wrote:
> 我用的包是2.0的,我就是建立一个JAVA工程,然后添加外置包,就是CXF2.0 lib下面的包。非常喜欢这个讨论组,我在上海怎么都没有发现在
> 用webservice的人呀。都不多呀。汗。。。。。。。。。。。。。。不知什么原因。上面的那个兄弟,我可以加你的MSN吗。我的是

> yunjit...@hotmail.com,想向你学习。

有问题就多上论坛上问吧。
在北京这边开发CXF的人都上这个论坛。

cxf-zh

unread,
Aug 31, 2007, 7:18:34 AM8/31/07
to cxf-zh
非常谢谢上面的朋友的提示,果然是版本不同导致运行不成功。现在改为2.0.1后,就可以成功运行,这对我初学者来说,是很大的鼓励!谢谢。

cxf-zh

unread,
Aug 31, 2007, 8:37:29 AM8/31/07
to cxf-zh

willem我看了你的博客。http://willem.bokeland.com/blog/,写得很好的。学到了好多。好后悔晚点认识
你。willem能不能推荐我初学者web service看哪些资料和网站好一些。我比较爱看www.csdn.net
www.javaeye.com,还有一些开源的网站,但是就是只知一些大体架构,很难从细节提高上去。对于web service。想请教
willem

willem

unread,
Aug 31, 2007, 10:20:49 AM8/31/07
to cxf-zh
推荐你看看 下面两本书

The Java Web Services Tutorial
http://java.sun.com/webservices/docs/2.0/tutorial/doc/
带领你如何使用Jaxws API

SOA: Using Java Web Services
http://soabook.com/
这本书介绍了很多Java Web Services框架实现细节的东西(很务实),特别是对JAXWS 系列的规范有比较详细的介绍,同时书中还给出
了几个实例。
下面是从Glen blog中抄的介绍 http://www.jroller.com/gmazza/entry/soa_using_java_web_services

Strengths of this book:

1. Good introductions and working code to Yahoo! Shopping RESTful
web services as well as eBay and Amazon SOAP-based web services are
provided in Chapter 9. This provides a solid starting point for
readers to move beyond book knowledge and start practicing with these
publicly available API's.
2. Fairly detailed code samples to work with, covering a broad
range of topics, which provide another good starting point for
developers.
3. I have often gone back to the book to find details or review
certain topics, so have found that it continues to serve as a good
reference after you are done reading it.

还有就是
FREE Web Services Training - 3rd session
http://blogs.sun.com/arungupta/entry/free_web_services_training_3rd


On Aug 31, 8:37 pm, cxf-zh <yunjit...@gmail.com> wrote:
> willem我看了你的博客。http://willem.bokeland.com/blog/,写得很好的。学到了好多。好后悔晚点认识

> 你。willem能不能推荐我初学者web service看哪些资料和网站好一些。我比较爱看www.csdn.netwww.javaeye.com,还有一些开源的网站,但是就是只知一些大体架构,很难从细节提高上去。对于web service。想请教
> willem

Reply all
Reply to author
Forward
0 new messages