我们看到我们的WebService已经布署成功了,我们再看看它的WSDL信息:
- <?xml version="1.0" encoding="UTF-8"?>
- <wsdl:definitions targetNamespace="http://cn.com.pansky/SayHiService" xmlns:tns="http://cn.com.pansky/SayHiService" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:types>
- <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://cn.com.pansky/SayHiService">
- <xsd:element name="sayHi">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element maxOccurs="1" minOccurs="1" name="in0" nillable="true" type="xsd:string"/>
- </xsd:sequence>
- </xsd:complexType>
- </xsd:element>
- <xsd:element name="sayHiResponse">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element maxOccurs="1" minOccurs="1" name="out" nillable="true" type="xsd:string"/>
- </xsd:sequence>
- </xsd:complexType>
- </xsd:element>
- </xsd:schema>
- </wsdl:types>
- <wsdl:message name="sayHiRequest">
- <wsdl:part name="parameters" element="tns:sayHi">
- </wsdl:part>
- </wsdl:message>
- <wsdl:message name="sayHiResponse">
- <wsdl:part name="parameters" element="tns:sayHiResponse">
- </wsdl:part>
- </wsdl:message>
- <wsdl:portType name="SayHiServicePortType">
- <wsdl:operation name="sayHi">
- <wsdl:input name="sayHiRequest" message="tns:sayHiRequest">
- </wsdl:input>
- <wsdl:output name="sayHiResponse" message="tns:sayHiResponse">
- </wsdl:output>
- </wsdl:operation>
- </wsdl:portType>
- <wsdl:binding name="SayHiServiceHttpBinding" type="tns:SayHiServicePortType">
- <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
- <wsdl:operation name="sayHi">
- <wsdlsoap:operation soapAction=""/>
- <wsdl:input name="sayHiRequest">
- <wsdlsoap:body use="literal"/>
- </wsdl:input>
- <wsdl:output name="sayHiResponse">
- <wsdlsoap:body use="literal"/>
- </wsdl:output>
- </wsdl:operation>
- </wsdl:binding>
- <wsdl:service name="SayHiService">
- <wsdl:port name="SayHiServiceHttpPort" binding="tns:SayHiServiceHttpBinding">
- <wsdlsoap:address location="http://localhost/stove/services/SayHiService"/>
- </wsdl:port>
- </wsdl:service>
- </wsdl:definitions>
这个文件跟我们用Axis生成的基本是一样的。
5、享受美味的时刻
WebService这道大餐算是烹制好了,现在是享用美餐的时候了。
我们写一个客户端吃掉这道大餐:
- package cn.com.pansky.webservice.xfire.study;
- import java.net.MalformedURLException;
- import java.util.Map;
- 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;
- import org.codehaus.xfire.transport.http.CommonsHttpMessageSender;
- public class SayHiClient{
- public static void main(String args[]) {
- String serviceURL = "http://localhost/stove/services/SayHiService";
- Service serviceModel = new ObjectServiceFactory().create(SayHiService.class,null,"http://cn.com.pansky/SayHiService",null);
- XFireProxyFactory serviceFactory = new XFireProxyFactory();
- try{
- SayHiService service = (SayHiService) serviceFactory.create(serviceModel, serviceURL);
- Client client = Client.getInstance(service);
- //client.addOutHandler(new OutHeaderHandler());
- // disable timeout
- client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, "1");
- String hello = service.sayHi("张山疯");
- System.out.println("服务器对[张山疯] 的回答是:" + hello );
- hello = service.sayHi(null);
- System.out.println("服务器胡言乱语说:" + hello );
- } catch (MalformedURLException e) {
- e.printStackTrace();
- }
- }
- }
编译这个类,再执行一下,服务器服务的结果是:
2008-5-22 17:39:17 org.apache.commons.httpclient.HttpMethodBase writeRequest
信息: 100 (continue) read timeout. Resume sending the request
2008-5-22 17:39:17 org.apache.commons.httpclient.HttpMethodBase readResponse
信息: Discarding unexpected response: HTTP/1.1 100 Continue
服务器对[张山疯] 的回答是:张山疯, 你吃了吗?没吃回家吃去吧。
2008-5-22 17:39:20 org.apache.commons.httpclient.HttpMethodBase writeRequest
信息: 100 (continue) read timeout. Resume sending the request
2008-5-22 17:39:20 org.apache.commons.httpclient.HttpMethodBase readResponse
信息: Discarding unexpected response: HTTP/1.1 100 Continue
服务器胡言乱语说:连名字也不肯告诉我吗?
好了,WebService布署成功。
下课!