MISC SP订购通知接口

本文介绍了一种从输入流中接收MISC报文的方法,并详细解析了报文内容,将其转换为易于操作的对象形式。同时,给出了响应报文的构造过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一步:接收MISC报文

            string sXmlMessage = "";
            // string Temp = "";
            System.IO.Stream bSoapMessage;
            System.Text.Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
            bSoapMessage = Request.InputStream;

            byte[] read = new byte[4096];
            int numBytesRead = 0;
            int nBytes = bSoapMessage.Read(read, numBytesRead, 4096);

            if (nBytes > 0)
            {
                while (nBytes > 0)
                {
                    numBytesRead += nBytes;
                    sXmlMessage += encode.GetString(read, 0, nBytes);
                    nBytes = bSoapMessage.Read(read, numBytesRead, 4096);
                }

               //sXmlMessage就是接收到的报文
                 

          }

第二步:解析报文

首先定义几个重要的类文件

    public class Address_info
    {

        private string deviceType;

        public string DeviceType
        {
            get { return deviceType; }
            set { deviceType = value; }
        }


        private string deviceID;

        public string DeviceID
        {
            get { return deviceID; }
            set { deviceID = value; }
        }
    }

    public class User_ID_info
    {

        private string userIDType;

        public string UserIDType
        {
            get { return userIDType; }
            set { userIDType = value; }
        }


        private string mSISDN;

        public string MSISDN
        {
            get { return mSISDN; }
            set { mSISDN = value; }
        }


        private string pseudoCode;

        public string PseudoCode
        {
            get { return pseudoCode; }
            set { pseudoCode = value; }
        }

    }

    public class SyncOrderRelationReqType
    {

        private string transactionID;

        public string TransactionID
        {
            get { return transactionID; }
            set { transactionID = value; }
        }

        private string version;

        public string Version
        {
            get { return version; }
            set { version = value; }
        }

        private string msgType;

        public string MsgType
        {
            get { return msgType; }
            set { msgType = value; }
        }


        private Address_info send_Address;

        public Address_info Send_Address
        {
            get { return send_Address; }
            set { send_Address = value; }
        }


        private Address_info dest_Address;

        public Address_info Dest_Address
        {
            get { return dest_Address; }
            set { dest_Address = value; }
        }


        private User_ID_info feeUser_ID;

        public User_ID_info FeeUser_ID
        {
            get { return feeUser_ID; }
            set { feeUser_ID = value; }
        }


        private User_ID_info destUser_ID;

        public User_ID_info DestUser_ID
        {
            get { return destUser_ID; }
            set { destUser_ID = value; }
        }


        private string linkID;

        public string LinkID
        {
            get { return linkID; }
            set { linkID = value; }
        }


        private string actionID;

        public string ActionID
        {
            get { return actionID; }
            set { actionID = value; }
        }


        private string actionReasonID;

        public string ActionReasonID
        {
            get { return actionReasonID; }
            set { actionReasonID = value; }
        }


        private string sPID;

        public string SPID
        {
            get { return sPID; }
            set { sPID = value; }
        }


        private string sPServiceID;

        public string SPServiceID
        {
            get { return sPServiceID; }
            set { sPServiceID = value; }
        }


        private string accessMode;

        public string AccessMode
        {
            get { return accessMode; }
            set { accessMode = value; }
        }


        private string featureStr;

        public string FeatureStr
        {
            get { return featureStr; }
            set { featureStr = value; }
        }
    }

   解析xml文件

        public static SyncOrderRelationReqType GetSyncOrderRelationReq(string sXml)
        {
            SyncOrderRelationReqType req = new SyncOrderRelationReqType();
            req.Send_Address = new Address_info();
            req.Dest_Address = new Address_info();
            req.FeeUser_ID = new User_ID_info();
            req.DestUser_ID = new User_ID_info();
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(sXml);
                XmlNode root = xmlDoc["SOAP-ENV:Envelope"]["SOAP-ENV:Header"];
                XmlNode child = root["TransactionID"]; //两种情况都试
                if (child == null)
                    child = root["dsmp:TransactionID"];
                req.TransactionID = child.InnerText;
                Util.WriteLog("TransactionID:" + req.TransactionID, "d://pro.txt");

                child = xmlDoc["SOAP-ENV:Envelope"]["SOAP-ENV:Body"]["SyncOrderRelationReq"];
                if (child == null)
                    child = xmlDoc["SOAP-ENV:Envelope"]["SOAP-ENV:Body"]["dsmp:SyncOrderRelationReq"];
                root = child;
                req.Version = root["Version"].InnerText;
               // Util.WriteLog("Version:"+req.Version, "d://pro.txt");
                req.MsgType = root["MsgType"].InnerText;
              //  Util.WriteLog("MsgType:"+req.MsgType, "d://pro.txt");

                req.Send_Address.DeviceType = root["Send_Address"]["DeviceType"].InnerText;
              //  Util.WriteLog("Send_Address.DeviceType:" + req.Send_Address.DeviceType, "d://pro.txt");
                req.Send_Address.DeviceID = root["Send_Address"]["DeviceID"].InnerText;
              //  Util.WriteLog("Send_Address.DeviceID:"+req.Send_Address.DeviceID, "d://pro.txt");

                req.Dest_Address.DeviceType = root["Dest_Address"]["DeviceType"].InnerText;
              //  Util.WriteLog("Dest_Address.DeviceType:" + req.Dest_Address.DeviceType, "d://pro.txt");

                req.Dest_Address.DeviceID = root["Dest_Address"]["DeviceID"].InnerText;
               // Util.WriteLog("Dest_Address.DeviceID:" + req.Dest_Address.DeviceID, "d://pro.txt");

                req.FeeUser_ID.UserIDType = root["FeeUser_ID"]["UserIDType"].InnerText;
               // Util.WriteLog("FeeUser_ID.UserIDType:"+req.FeeUser_ID.UserIDType, "d://pro.txt");

                req.FeeUser_ID.MSISDN = root["FeeUser_ID"]["MSISDN"].InnerText;
                //Util.WriteLog("FeeUser_ID.MSISDN:" + req.FeeUser_ID.MSISDN, "d://pro.txt");

                req.FeeUser_ID.PseudoCode =root["FeeUser_ID"]["PseudoCode"].InnerText;
               // Util.WriteLog("FeeUser_ID.PseudoCode:" + req.FeeUser_ID.PseudoCode, "d://pro.txt");

                req.DestUser_ID.UserIDType = root["DestUser_ID"]["UserIDType"].InnerText;
               // Util.WriteLog("DestUser_ID.UserIDType:" + req.DestUser_ID.UserIDType, "d://pro.txt");

                req.DestUser_ID.MSISDN = root["DestUser_ID"]["MSISDN"].InnerText;
               // Util.WriteLog("DestUser_ID.MSISDN:" + req.DestUser_ID.MSISDN, "d://pro.txt");

                req.DestUser_ID.PseudoCode =root["DestUser_ID"]["PseudoCode"].InnerText;
              //  Util.WriteLog("DestUser_ID.PseudoCode:" + req.DestUser_ID.PseudoCode, "d://pro.txt");

                child = root["LinkID"];
                if (child != null)
                {
                    req.LinkID = child.InnerText;

                   // Util.WriteLog("LinkID:" + req.LinkID, "d://pro.txt");
                }

                req.ActionID = root["ActionID"].InnerText;
               // Util.WriteLog("ActionID:" + req.ActionID, "d://pro.txt");

                req.ActionReasonID = root["ActionReasonID"].InnerText;
              //  Util.WriteLog("ActionReasonID:" + req.ActionReasonID, "d://pro.txt");

                child = root["SPID"];
                if (child != null)
                {
                    req.SPID = child.InnerText;
                   // Util.WriteLog("SPID:" + req.SPID, "d://pro.txt");
                }
                req.SPServiceID = root["SPServiceID"].InnerText;
              //  Util.WriteLog("SPServiceID:" + req.SPServiceID, "d://pro.txt");
                child = root["AccessMode"];
                if (child != null)
                {
                    req.AccessMode = child.InnerText;
                  //  Util.WriteLog("AccessMode:" + req.AccessMode, "d://pro.txt");
                }
                child = root["FeatureStr"];
                if (child != null)
                {
                    req.FeatureStr = child.InnerText;
                   // Util.WriteLog("FeatureStr:" + req.FeatureStr, "d://pro.txt");
                }

            }
            catch (XmlException eXml)
            {
                string msg = eXml.ToString();
                return null;
            }
            catch (Exception e)
            {
                string msg = e.ToString();
                return null;
            }
            return req;
        }

第三步:解析之后插入数据库,结合自己的业务,这里不做详细解释

第四步:响应

                sXmlMessage = @"<?xml version=""1.0"" encoding=""utf-8""?>";
                sXmlMessage += @"<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/"">";

                sXmlMessage += @"<SOAP-ENV:Header><TransactionID xmlns=""http://www.monternet.com/dsmp/schemas/"">" + TransactionID + "</TransactionID> </SOAP-ENV:Header>";

                sXmlMessage += @"<SOAP-ENV:Body><SyncOrderRelationResp xmlns=""http://www.monternet.com/dsmp/schemas/""><Version>1.5.0</Version><MsgType>SyncOrderRelationResp</MsgType><hRet>" + Ret + "</hRet></SyncOrderRelationResp></SOAP-ENV:Body></SOAP-ENV:Envelope>";

                Response.ContentType = "text/xml";
                Response.Charset = "utf-8";
                Response.Write(sXmlMessage);

 

到此为止!

希望各位大侠批评指正!谢谢

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值