QName HelloWorld ---记CXF中QName的使用
一. 什么是QName
二. QName在CXF中的使用直接上代码,我使用的是apache-cxf-2.4.6. 服务器端(注意我测试的时候service接口,service实现类 和发布service的类放在同一包里,实际使用过程中可以放在不同的包里) 1. 服务器端代码:1.1 service接口 package com.server; import javax.jws.WebParam; import javax.jws.WebService; @WebService public interface IHelloWorldService { public String sayHello(@WebParam(name="text") String name); } ? 1.2 service 实现类 package com.server; import javax.jws.WebService; @WebService(serviceName="Helloworld") public class HelloWorldService implements IHelloWorldService{ public String sayHello( String name){ return name + "say : Hello Service."; } } 1.3 发布service的类 package com.server; import javax.xml.ws.Endpoint; public class DeployHelloWorldService { public static void main(String[] args) throws Exception{ IHelloWorldService service = new HelloWorldService(); String address = "http://localhost:9000/helloWorld"; Endpoint.publish(address,service); System.out.println("service ready ..."); } }?1.4 运行发布的类后,在IE中输入:http://localhost:9000/helloWorld?wsdl就可以看到如下wsdl:?<?xml version="1.0" encoding="UTF-8" ?> - <wsdl:definitions name="Helloworld" targetNamespace="http://server.com/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://server.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> - <wsdl:types> - <xs:schema elementFormDefault="unqualified" targetNamespace="http://server.com/" version="1.0" xmlns:tns="http://server.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="sayHello" type="tns:sayHello" /> <xs:element name="sayHelloResponse" type="tns:sayHelloResponse" /> - <xs:complexType name="sayHello"> - <xs:sequence> <xs:element minOccurs="0" name="text" type="xs:string" /> </xs:sequence> </xs:complexType> - <xs:complexType name="sayHelloResponse"> - <xs:sequence> <xs:element minOccurs="0" name="return" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:schema> </wsdl:types> - <wsdl:message name="sayHelloResponse"> <wsdl:part element="tns:sayHelloResponse" name="parameters" /> </wsdl:message> - <wsdl:message name="sayHello"> <wsdl:part element="tns:sayHello" name="parameters" /> </wsdl:message> - <wsdl:portType name="IHelloWorldService"> - <wsdl:operation name="sayHello"> <wsdl:input message="tns:sayHello" name="sayHello" /> <wsdl:output message="tns:sayHelloResponse" name="sayHelloResponse" /> </wsdl:operation> </wsdl:portType> - <wsdl:binding name="HelloworldSoapBinding" type="tns:IHelloWorldService"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> - <wsdl:operation name="sayHello"> <soap:operation soapAction="" style="document" /> - <wsdl:input name="sayHello"> <soap:body use="literal" /> </wsdl:input> - <wsdl:output name="sayHelloResponse"> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding> - <wsdl:service name="Helloworld"> - <wsdl:port binding="tns:HelloworldSoapBinding" name="HelloWorldServicePort"> <soap:address location="http://localhost:9000/helloWorld" /> </wsdl:port> </wsdl:service> </wsdl:definitions> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |