上一篇文章是關於 CMPP3.0 的 C# 實現,我為了測試其中的 PROVISION 接口,利用了 System.Net.HttpWebRequest 類將《MISC系統短信SP接入指南-接口改造分冊》文檔中的示例 xml 發送到了 WEB 服務,並從 WEB 服務返回了對應的 Resp 包(也是一段 xml),下面就將代碼貼出來:
1、SyncOrderRelationReq 包的 xml 內容:
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Header>
<TransactionID xmlns="http://www.monternet.com/dsmp/schemas/">00110318384464</TransactionID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<SyncOrderRelationReq xmlns="http://www.monternet.com/dsmp/schemas/">
<Version>1.5.0</Version>
<MsgType>SyncOrderRelationReq</MsgType>
<Send_Address>
<DeviceType>0</DeviceType>
<DeviceID>0011</DeviceID>
</Send_Address>
<Dest_Address>
<DeviceType>400</DeviceType>
<DeviceID>0</DeviceID>
</Dest_Address>
<FeeUser_ID>
<UserIDType>1</UserIDType>
<MSISDN>13456781234</MSISDN>
<PseudoCode></PseudoCode>
</FeeUser_ID>
<DestUser_ID>
<UserIDType>1</UserIDType>
<MSISDN>13456781234</MSISDN>
<PseudoCode></PseudoCode>
</DestUser_ID>
<LinkID>SP</LinkID>
<ActionID>1</ActionID>
<ActionReasonID>1</ActionReasonID>
<SPID>419000</SPID>
<SPServiceID>-YYXXYYXX</SPServiceID>
<AccessMode>3</AccessMode>
<FeatureStr>MTA2NjIxNDQgREE=</FeatureStr>
</SyncOrderRelationReq>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
2、HttpWebRequest 調用 WEB 服務的代碼:
System.Xml.XmlDocument doc = new XmlDocument();
doc.Load("c:\\SyncOrderRelationReq.xml");
MemoryStream ms = new MemoryStream();
doc.Save(ms);
System.Net.HttpWebRequest r = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://localhost/websrv/dsmp.asmx");
r.Method = "POST";
r.ContentType = @"text/xml;charset=utf-8";
r.Headers.Add("SOAPAction", "\"" + "sim.SyncOrderRelation" + "\"");
r.Credentials = System.Net.CredentialCache.DefaultCredentials;
byte[] bytes = ms.ToArray();
r.ContentLength = bytes.Length;
Stream s = r.GetRequestStream();
s.Write(bytes, 0, bytes.Length);
s.Close();
StreamReader sr = new StreamReader(r.GetResponse().GetResponseStream());
String retXml = sr.ReadToEnd();
sr.Close();
doc = new XmlDocument();
doc.LoadXml(retXml);
doc.Save("c:\\SyncOrderRelationResp.xml");
這只是一個利用 HttpWebRequest 調用 WEB 服務的小例子,只需要將上面的那段 xml 保存為 c 盤下的 SyncOrderRelationReq.xml 文件中,調用後就會將 WEB 服務的返回結果保存在 c 盤的 SyncOrderRelationResp.xml 中了。