----------------------------------------------------------------
/**
* 版权: 石太祥 [ E.Alpha ] 所有 ;
*
* email: ealpha(AT)msn(DOT)com ;
* msn: ealpha(AT)msn(DOT)com ;
* QQ : 9690501
*
* 所有转载请注明本信息!
*/
----------------------------------------------------------------
说明 : 系统采用AXIS,如果无axis知识,建议可以到IBM开发者上搜索相关 AXIS 文档浏览
—————————————————————————————————————
1、 配置好AXIS
2、 将wsdl 文件 copy 到 /TOMCAT_HOME/webapps/axis/WEB-INF 下
Wsdl 文件由于MISC提供的不能生成 header ;经过修改以后的新的WSDL文件为:
<definitions xmlns:ws="http://www.monternet.com/dsmp/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.ort/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:dsmp="http://www.monternet.com/dsmp/schemas/" targetNamespace="http://www.monternet.com/dsmp/wsdl/"> <types> <schema targetNamespace="http://www.monternet.com/dsmp/schemas/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" attributeFormDefault="unqualified"> <complexType name="address_info_schema"> <sequence> <element name="DeviceType" type="xsd:integer"/> <element name="DeviceID" type="xsd:string"/> </sequence> </complexType> <complexType name="user_id_schema"> <sequence> <element name="UserIDType" type="xsd:integer"/> <element name="MSISDN" type="xsd:string"/> <element name="PseudoCode" type="xsd:base64Binary"/> </sequence> </complexType> <!-- request & response -->
<element name="TransactionID" type="xsd:string"/>
<element name="SyncOrderRelationReq" type="dsmp:SyncOrderRelationReqType"/> <complexType name="SyncOrderRelationReqType"> <sequence> <element name="Version" type="xsd:string"/> <element name="MsgType" type="xsd:string"/> <element name="Send_Address" type="dsmp:address_info_schema"/> <element name="Dest_Address" type="dsmp:address_info_schema"/> <element name="FeeUser_ID" type="dsmp:user_id_schema"/> <element name="DestUser_ID" type="dsmp:user_id_schema"/> <element name="LinkID" type="xsd:string" minOccurs="0"/> <element name="ActionID" type="xsd:integer"/> <element name="ActionReasonID" type="xsd:integer"/> <element name="SPID" type="xsd:string" minOccurs="0"/> <element name="SPServiceID" type="xsd:string"/> <element name="AccessMode" type="xsd:integer" minOccurs="0"/> <element name="FeatureStr" type="xsd:base64Binary" minOccurs="0"/> </sequence> </complexType> <element name="SyncOrderRelationResp" type="dsmp:SyncOrderRelationRespType"/> <complexType name="SyncOrderRelationRespType"> <sequence> <element name="Version" type="xsd:string"/> <element name="MsgType" type="xsd:string"/> <element name="hRet" type="xsd:integer"/> </sequence> </complexType> </schema> </types>
<message name="ma.SyncOrderRelationReq"> <part name="SyncOrderRelationInput" element="dsmp:SyncOrderRelationReq"/> <part name="TransactionIDInput" element="dsmp:TransactionID"/> </message>
<message name="ma.SyncOrderRelationResp"> <part name="SyncOrderRelationOutput" element="dsmp:SyncOrderRelationResp"/> <part name="TransactionIDOut" element="dsmp:TransactionID"/> </message>
<portType name="maPort"> <operation name="SyncOrderRelation"> <input message="ws:ma.SyncOrderRelationReq"/> <output message="ws:ma.SyncOrderRelationResp"/> </operation> </portType>
<binding name="maPortBinding" type="ws:maPort"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="SyncOrderRelation"> <soap:operation style="document" soapAction="sim.SyncOrderRelation"/> <input> <soap:body use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://www.monternet.com/dsmp/schemas/"/> <soap:header message="ws:ma.SyncOrderRelationReq" part="TransactionIDInput" use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding" namespace="http://www.w3.org/2001/XMLSchema"/> </input> <output> <soap:body use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://www.monternet.com/dsmp/schemas/"/> <soap:header style="document" message="ws:ma.SyncOrderRelationResp" part="TransactionIDOut" use="literal" encodingStyle="http://schemas.xmlsoap.org/soap/encoding" namespace="http://www.w3.org/2001/XMLSchema"/> </output> </operation> </binding> <service name="dsmp"> <port name="maPort" binding="ws:maPortBinding"> <soap:address location="http://localhost/axis/services/maPort"/> </port> </service> </definitions> |
3、 生成客户端,服务端代码:
使用命令:Java -Djava.ext.dirs=lib org.apache.axis.wsdl.WSDL2Java --server-side --skeletonDeploy true dsmp.wsdl
4、 deploy.wsdd 用来发布service
MaPortBindingImpl.java 服务短编程使用
MaPortBindingStub.java 客户端编程使用
5、 建立服务:
使用命令 :java org.apache.axis.utils.Admin client|server deploy.wsdd
建立服务端和客户端的服务。
6、 编写客户端测试代码:
package com.smsmail.misc;
import java.math.BigInteger; import java.net.URL;
import javax.xml.rpc.holders.StringHolder;
import com.monternet.www.dsmp.schemas.Address_info_schema; import com.monternet.www.dsmp.schemas.SyncOrderRelationReqType; import com.monternet.www.dsmp.schemas.SyncOrderRelationRespType; import com.monternet.www.dsmp.schemas.User_id_schema; import com.monternet.www.dsmp.schemas.holders.SyncOrderRelationRespTypeHolder; import com.monternet.www.dsmp.wsdl.MaPortBindingStub;
/* * 移动MISC系统升级,SP客户端测试环境 */ public class ClientTest {
private static BigInteger msg;
public static void main(String[] args) {
MaPortBindingStub binding = null; SyncOrderRelationRespType value = null; SyncOrderRelationReqType req=new SyncOrderRelationReqType(); SyncOrderRelationRespTypeHolder syncOrderRelationOutput = new SyncOrderRelationRespTypeHolder(); StringHolder transactionIDOut = new StringHolder();
/** * * TransactionID 由返回的provision包里面的对应字段来决定,然后放到响应包里面的对应字段 * TransactionID不是sp生成的 * */
// 根据 - 数据业务管理平台接口规范- 1.5.1 定义。可以参考schemas 下的类文件 BigInteger devicetypeSend_Address = BigInteger.valueOf(201); BigInteger devicetypeDest_Address = BigInteger.valueOf(0); BigInteger UserIDTypeFeeUser_ID = BigInteger.valueOf(1); BigInteger ActionID = BigInteger.valueOf(1); BigInteger ActionReasonID = BigInteger.valueOf(1); BigInteger AccessMode = BigInteger.valueOf(3);
// 对于一些固定的值来决定
Address_info_schema Send_Address = new Address_info_schema(); Send_Address.setDeviceID("dev"); Send_Address.setDeviceType(devicetypeSend_Address);
Address_info_schema Dest_Address = new Address_info_schema(); Dest_Address.setDeviceID("0011"); Dest_Address.setDeviceType(devicetypeDest_Address);
User_id_schema FeeUser_ID = new User_id_schema(); FeeUser_ID.setMSISDN("13817931870"); FeeUser_ID.setUserIDType(UserIDTypeFeeUser_ID);
User_id_schema DestUser_ID = new User_id_schema(); DestUser_ID.setMSISDN("13817931870"); DestUser_ID.setUserIDType(UserIDTypeFeeUser_ID);
/** * 给请求赋值 */
req.setMsgType("SubscribeServiceReq"); req.setVersion(" 1.5.0 "); req.setSend_Address(Send_Address); req.setDest_Address(Dest_Address); req.setFeeUser_ID(FeeUser_ID); req.setDestUser_ID(DestUser_ID); req.setLinkID(""); // 可选 req.setActionID(ActionID); req.setActionReasonID(ActionReasonID); req.setSPID("800001"); req.setSPServiceID("+021"); req.setAccessMode(AccessMode);
try { URL endpoint = new URL("http://localhost:808/axis/services/maPort"); //详细见说明1 和说明 2 说明3 binding = (MaPortBindingStub) new com.monternet.www.dsmp.wsdl.DsmpLocator().getmaPort(endpoint); binding.setTimeout(60000);
binding.syncOrderRelation(req,"27",syncOrderRelationOutput,transactionIDOut);
} catch (Exception e) { e.printStackTrace(); }
}
}
|
说明1、 该URL是在真实环境中提交给 MISC平台的地址;
说明2、 该URL指向本地的服务地址,一定要保证 访问该URL时候提示为:
maPortHi there, this is an AXIS service! Perhaps there will be a form for invoking the service here... |
说明3 、本出URL的地址中端口为 808 是因为在 TCPMonitor中设置 监听端口转发为 808。 如果不开启TCPMonitor 则直接设置为8080
7、 编写服务短返回代码
// 添加返回 SyncOrderRelationRespType ret = new SyncOrderRelationRespType();
BigInteger hret = BigInteger.valueOf(0);
ret.setMsgType("SubscribeServiceResp"); ret.setHRet(hret); ret.setVersion(" 1.5.0 "); //return null; |
8、 问题解决:
n 由于每次请求的SOAP 报文命名空间问题。
采用修改AXIS 1.2版本的源文件:源文件为 (该文件由网友提供,无源代码)
n 包含 xmls=““ 问题
修改 SerializationContextImpl.java 文件,按照如下修改
public String qName2String(QName qName, boolean writeNS) if (namespaceURI.length() == 0) { if ((prefix == null) || (prefix.length() == 0)) StringBuffer sb = new StringBuffer(prefix); |