一. 什么是QName
1.来历:qname是qualifiedname的简写
2.构成:由名字空间(namespace)前缀(prefix)以及冒号(:),还有一个元素名称构成
3.举例:<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:portTypename="IHelloWorldService"><wsdl:operation name="sayHello"><wsdl:inputmessage="tns:sayHello" name="sayHello" /><wsdl:outputmessage="tns:sayHelloResponse" name="sayHelloResponse" /></wsdl:operation></wsdl:portType></wsdl:definitions>以wsdl:portType为例:wsdl是名字空间前缀,portTpye是元素名称,wsdl:portType就是一个qname,其namespace是:http://server.com/
二. 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的类
- <pre class="java" name="code">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 ...");
- }
- }</pre>
- 1.4 运行发布的类后,在IE中输入:<a href="http://localhost:9000/helloWorld?wsdl" mce_href="http://localhost:9000/helloWorld?wsdl">http://localhost:9000/helloWorld?wsdl</a>就可以看到如下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>
2. 客户端使用QName调用WebService的代码
- package client;
- import javax.xml.namespace.QName;
- import javax.xml.ws.Service;
- import javax.xml.ws.soap.SOAPBinding;
- import com.server.IHelloWorldService;
- public class HelloWorldServiceClient {
- /**
- * namespaceURI即为:wsdl:definitions name="Helloworld" targetNamespace="http://server.com/"...
- * 中的targetNamespace.
- * 如果服务器端的service接口和类不在同一个包中时:
- * namespaceURI即为wsdl:import中的namespace
- * <wsdl:import location="http://localhost:9000/helloWorld?wsdl=IHelloWorldService.wsdl" namespace="http://inter.server.com/" />
- */
- private static String namespaceURI = "http://server.com/";
- private static final QName SERVICE_NAME = new QName(namespaceURI,"IHelloWorldService");
- private static final QName PORT_NAME = new QName(namespaceURI,"IHelloWorldServicePort");
- public static void main(String[] args) {
- Service service = Service.create(SERVICE_NAME);
- String endpointAddress = "http://localhost:9000/helloWorld";
- service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
- IHelloWorldService clientService = service.getPort(IHelloWorldService.class);
- String result = clientService.sayHello("hello QName");
- System.out.println(result);
- }
运行该类就可以通过QName调用到Server端的service
注意以下几点:
2.1 namespaceURI 为:wsdl:definitions中的targetNamespace的值,在本例中就是http://server.com/
2.2.serviceName 为: wdsl中的IHelloWorldService对对应的portType 的name ,使用<wsdl:service name="Helloworld">中的Helloworld也可以,具体原因也说不上来。serviceName使用其他错误的值,该程序
也可以正常运行,搞不懂了。
2.3.protName 为wdsl中的IHelloWorldService对对应的portType 的name + “Port”即IHelloWorldServicePort,我估计之所以这么使用是因为客户端是通过IHelloWorldService调用的原因。
使用HelloworldPort会抛异常:
“Caused by: java.net.MalformedURLException: Invalid address. Endpoint address cannot be null.”
这个PortName也不是<wsdl:port binding="tns:HelloworldSoapBinding" name="HelloWorldServicePort"> 中的HelloWorldServicePort,如果使用HelloWorldServicePort也回抛出上面的异常。
总结一点,在使用QName的过程中nameSpaceUrl 和PortName 不能写错,否则会导致调用时抛异常。
相关推荐
本备忘录介绍域名系统(Domain Name System, DNS),文中忽略了许多细节,这些细节可在姊妹篇RFC“域名---实现和规范”[RFC-1035]中找到。RFC1035假设读者熟悉本备忘录中讨论的概念。 目录 第1章 本备忘录状态 第2章 ...
qname.jar qname.jar
1. Add the QName JAR file (qname.jar) into the WEB-INF/lib folder in your WAR file 2. Add a file weblogic.xml into the WEB-INF folder in your WAR file Below is an example weblogic.xml file: <!DOCTYPE ...
xmlbeans-qname.jar
weblogic javax/xml/namespace/QName报错-附件资源
这个问题曾困扰了我一段时间,无意中看到了网上的一篇文章,看完后真是觉得惭愧啊!还是平时的粗心大意造成的啊!
js-qname 简单的QName(命名空间URI +本地名称)JavaScript的对象实现
jsr173_1.0_api.jar rasolver.jar xbean.jar xbean_xpath.jar xmlbeans-qname.jar xmlpublic.jar
中,这是“sudo apt-get install jq”。)您还需要 Q 上的固件版本,该版本在查询灯泡列表时不会锁定。 目前这似乎只有1.0.00_r341。 最终用户脚本: Qcolor.sh - 从 GUI 设置灯泡颜色。 (现在您需要编辑脚本以添加...
此压缩包不仅仅只有文档,还有axis1.4相关资源。详细描述了如何在tomacat6.0下发布webService,并以此为基础,进一步...而且网上多半是一些helloworld的范例,但实际项目工程的发布又和发布helloworld范例是不同的。
xbeanetc.rar 该压缩包包括如下jar包: xbean.jar xbean_xpath.jar xerces.jar xercesImpl.jar xercesImpl-2.6.2.jar xml-apis.jar xml-apis1.jar xml-apis-2.6.2.jar xmlbeans-qname.jar...
内附dom4j-1.6.1.rar(内有dom4j-1.6.1.jar包和附加包),解析xml详解文档,解析xml的java源码。
poi-4.1.2需要的jar包,需要使用的朋友可以直接用,从maven库整理出来的。
使用axis1.3构建自己的SOAP应用程序源码; 详细介绍了如何使用ant脚本构建SOAP,以及如何测试SOAP接口。 详细可查看本人博客:使用axis1.3构建自己的SOAP应用程序源码
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if (...
报错项目加入geronimo-jaxws_2.2_spec-1.1和jaxb-api-2.2.5jar包 可以解决javax.xml.ws.Service报错The constructor Service(URL,QName,WebServiceFeature[]) is undefined。
0、包含xbean.jar xmlbeans-qname.jar jsr173_1.0_api.jar resolver.jar 1、使用xmlbeans通过xsd文件创建bean所需jar包; 2、xmlbeans可以去git上下载:git://git.apache.org/xmlbeans.git 3、命令如: D:\xmlbeans\...
今天我们来看看AS3中新的XML处理方法:E4X,直到现在,ECMA脚本语言规范(ECMA-...这些类和方法的集合并命名为E4X("ECMAScript for XML"),ActionScript 3.0包括如下新的E4X类: XML、XMLList、 QName和Namespace。
a master paper about repository of bpel