xfire客户端代码可以利用工具生成,但有些情况下工具没法生成,无法只能手工编写。本文记录手工编写客户端代码过程。
目录:
目录:
- QName的解释
- 一、分析自动生成的代码
- 二、自定义生成的代码
QName的解释
1.来历:qname是
qualified name 的简写
2.构成:由名字空间(NS)前缀(prefix)以及冒号(:),还有一个元素名称构成
3.举例:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
version="1.0">
<xsl:template match="foo">
<hr/>
</xsl:template>
</xsl:stylesheet>
xsl是名字空间前缀,template是元素名称,xsl:template 就是一个qname。代表<xsl:template match="foo">标签
4.总结:qname无非是有着特定格式的xml元素,其作用主要是增加了名字空间,比如有同样的元素名称,而名字空间不同的情况。举例如下
一、分析自动生成的代码。2个包中文件如下
2.构成:由名字空间(NS)前缀(prefix)以及冒号(:),还有一个元素名称构成
3.举例:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
version="1.0">
<xsl:template match="foo">
<hr/>
</xsl:template>
</xsl:stylesheet>
xsl是名字空间前缀,template是元素名称,xsl:template 就是一个qname。代表<xsl:template match="foo">标签
4.总结:qname无非是有着特定格式的xml元素,其作用主要是增加了名字空间,比如有同样的元素名称,而名字空间不同的情况。举例如下
- 注:这是一段AS3的代码。很好说明问题。函数trace相当于println
- var xml:XML =// 定义一个XML对象
- <xml>
- <ns1:node xmlns:ns1="http://www.ticore.com/ns1"/>
- <ns2:node xmlns:ns2="http://www.ticore.com/ns2"/>
- <ns3:node xmlns:ns3="http://www.ticore.com/ns3"/>
- <ns4:node xmlns:ns4="http://www.ticore.com/ns4"/>
- </xml>;
-
- trace(xml[new QName("http://www.ticore.com/ns1", "node")].toXMLString());
- trace(xml.elements(new QName("http://www.ticore.com/ns2", "node")).toXMLString());
- trace(xml.descendants(new QName("http://www.ticore.com/ns3", "node")).toXMLString());
- trace(xml.child(new QName("http://www.ticore.com/ns4", "node")).toXMLString());
一、分析自动生成的代码。2个包中文件如下
com.reyosoft.app.webclient
XFireClientFactory.java
SigManager.java
SigManagerImpl.java
com.reyosoft.app.webclient.entity
package-info.java
ObjectFactory.java
SigServiceCategory.java
XFireClientFactory.java
SigManager.java
SigManagerImpl.java
com.reyosoft.app.webclient.entity
package-info.java
ObjectFactory.java
SigServiceCategory.java
1, package-info.java 看了就明白
@javax.xml.bind.annotation.XmlSchema(NS = "http://www.reyosoft.com/webservice")
package com.reyosoft.app.webclient.entity;
2, SigServiceCategory.java
package com.reyosoft.app.webclient.entity;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "NewComplexType1"
public class SigServiceCategory {
@XmlElement(name = "ESSC", required = true)
protected List<SigServiceCategory. Data > data;
public List<SigServiceCategory. Data > getData() {
if ( data == null) {
data = new ArrayList<SigServiceCategory. Data >();
}
return this. data ;
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = ""
public static class Data {
@XmlElement(name = "SCID", required = true)
protected String scid;
@XmlElement(name = "SCCategory", required = true)
protected String scCategory;
@XmlElement(name = "SCSub", required = true)
protected String scSub;
@XmlElement(name = "SCDesc", required = true)
protected String scDesc;
@XmlElement(required = true)
protected String sigNo;
省略setter和getter
}
}
"蓝色"代码是wsdl中对应的<wsdl:types>标签下的对应的值。例如 NewComplexType1 和 ESSC 对应
<wsdl:types>
<xsd:schema targetNS="" xmlns:tns="">
<xsd:complexType name="NewComplexType1">
<xsd:sequence>
<xsd:element name="ESSC" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="SCID"
type="xsd:string">
</xsd:element>
<xsd:element name="SCCategory"
type="xsd:string">
</xsd:element>
<xsd:element name="SCSub"
type="xsd:string">
</xsd:element>
<xsd:element name="SCDesc"
type="xsd:string">
</xsd:element>
<xsd:element name="sigNo"
type="xsd:string">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
........
<xsd:schema targetNS="" xmlns:tns="">
<xsd:complexType name="NewComplexType1">
<xsd:sequence>
<xsd:element name="ESSC" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="SCID"
type="xsd:string">
</xsd:element>
<xsd:element name="SCCategory"
type="xsd:string">
</xsd:element>
<xsd:element name="SCSub"
type="xsd:string">
</xsd:element>
<xsd:element name="SCDesc"
type="xsd:string">
</xsd:element>
<xsd:element name="sigNo"
type="xsd:string">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
........
3 , ObjectFactory.java
package com.reyosoft.app.webclient.entity;
import javax.xml.bind.annotation.XmlRegistry;
@XmlRegistry
public class ObjectFactory {
public ObjectFactory() {
}
public SigServiceCategory createNewComplexType1(){
return new SigServiceCategory();
}
public SigServiceCategory.Data createNewComplexType1ESSC(){
return new SigServiceCategory.Data();
}
}
请注意这里的两个函数名规则。不用我说明应该知道怎么回事了吧!
4, SigManager.java
package com.reyosoft.app.webclient;
@WebService(name = SIG_SN ,
targetNS = SIG_NS)
public interface SigManager {
@WebMethod(operationName = "getServiceCategory", action = SIG_NS + " es_sig/getServiceCategory")
@WebResult(name = "getServiceCategoryResponse", targetNS = SIG_NS)
public SigServiceCategory getServiceCategory(
@WebParam(name = "getServiceCategoryUN", targetNS = SIG_NS)
String getServiceCategoryUN,
@WebParam(name = "getServiceCategoryPW", targetNS = SIG_NS)
String getServiceCategoryPW);
}
5, SigManagerImpl.java
package com.reyosoft.app.webclient;
@WebService( serviceName = SIG_SN ,
targetNS = SIG_NS,
endpointInterface = "com.reyosoft.app.webclient.SigManager")
@SOAPBinding( style = SOAPBinding.Style.DOCUMENT,
use = SOAPBinding.Use.LITERAL,
parameterStyle = SOAPBinding.ParameterStyle.BARE)
public class SigManagerImpl implements SigManager{
/**
* {@inheritDoc}
*/
public SigServiceCategory getServiceCategory(String getServiceCategoryUN, String getServiceCategoryPW) {
throw new UnsupportedOperationException();
}
}
6, XFireClientFactory.java 不需要改动
二、手动添加。
模仿自动添加的样例,需要修改的地方我已经用下划线标识了。