예제 #1
0
        /// <summary>
        /// Create a new OCPP SOAP header.
        /// </summary>
        /// <param name="ChargeBoxIdentity">The unique identification of the charge box.</param>
        /// <param name="Action">The SOAP action.</param>
        /// <param name="MessageId">An unique message identification.</param>
        /// <param name="RelatesTo">The unique message identification of the related SOAP request.</param>
        /// <param name="From">The source URI of the SOAP message.</param>
        /// <param name="To">The destination URI of the SOAP message.</param>
        public SOAPHeader(ChargeBox_Id ChargeBoxIdentity,
                          String Action,
                          String MessageId,
                          String RelatesTo,
                          String From,
                          String To)
        {
            #region Initial checks

            if (ChargeBoxIdentity == null)
            {
                throw new ArgumentNullException(nameof(ChargeBoxIdentity), "The given charge box identification must not be null!");
            }

            if (Action.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Action), "The given SOAP action must not be null or empty!");
            }

            if (From.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(From), "The given SOAP message source must not be null or empty!");
            }

            if (To.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(To), "The given SOAP message destination must not be null or empty!");
            }

            #endregion

            this.ChargeBoxIdentity = ChargeBoxIdentity;
            this.Action            = Action;
            this.MessageId         = MessageId;
            this.RelatesTo         = RelatesTo;
            this.From = From;
            this.To   = To;
        }
예제 #2
0
        /// <summary>
        /// Encapsulate the given XML within a XML SOAP frame.
        /// </summary>
        /// <param name="ChargeBoxIdentity">The unique identification of the charge box.</param>
        /// <param name="Action">The SOAP action.</param>
        /// <param name="MessageId">An unique message identification.</param>
        /// <param name="RelatesTo">The unique message identification of the related SOAP request.</param>
        /// <param name="From">The source URI of the SOAP message.</param>
        /// <param name="To">The destination URI of the SOAP message.</param>
        /// <param name="SOAPBody">The internal XML for the SOAP body.</param>
        /// <param name="XMLNamespaces">An optional delegate to process the XML namespaces.</param>
        public static XElement Encapsulation(ChargeBox_Id ChargeBoxIdentity,
                                             String Action,
                                             String MessageId,
                                             String RelatesTo,
                                             String From,
                                             String To,
                                             XElement SOAPBody,
                                             XMLNamespacesDelegate XMLNamespaces = null)
        {
            #region Initial checks

            if (ChargeBoxIdentity == null)
            {
                throw new ArgumentNullException(nameof(ChargeBoxIdentity), "The given charge box identity must not be null!");
            }

            if (Action == null)
            {
                throw new ArgumentNullException(nameof(Action), "The given SOAP action must not be null!");
            }

            if (MessageId == null)
            {
                throw new ArgumentNullException(nameof(MessageId), "The given SOAP message identification must not be null!");
            }

            if (From == null)
            {
                throw new ArgumentNullException(nameof(From), "The given SOAP message source must not be null!");
            }

            if (To == null)
            {
                throw new ArgumentNullException(nameof(To), "The given SOAP message destination must not be null!");
            }

            if (SOAPBody == null)
            {
                throw new ArgumentNullException(nameof(SOAPBody), "The given XML must not be null!");
            }

            if (XMLNamespaces == null)
            {
                XMLNamespaces = xml => xml;
            }

            #endregion

            #region Documentation

            // <soap:Envelope xmlns:soap = "http://www.w3.org/2003/05/soap-envelope"
            //                xmlns:wsa  = "http://www.w3.org/2005/08/addressing"
            //                xmlns:ns   = "urn://Ocpp/Cs/2015/10/">
            //
            //    <soap:Header>
            //       <ns:chargeBoxIdentity>?</ns:chargeBoxIdentity>
            //       <wsa:Action soap:mustUnderstand="1">/Authorize</wsa:Action>
            //       <wsa:ReplyTo soap:mustUnderstand="1">
            //         <wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>
            //       </wsa:ReplyTo>
            //       <wsa:MessageID soap:mustUnderstand="1">uuid:516f7065-074c-4f4a-8b6d-fd3603d88e3d</wsa:MessageID>
            //       <wsa:RelatesTo soap:mustUnderstand="1">uuid:35245423-4545-4454-8454-f45243645672</wsa:MessageID>
            //       <wsa:To soap:mustUnderstand="1">http://127.0.0.1:2010/v1.6</wsa:To>
            //    </soap:Header>
            //
            //    <soap:Body>
            //       ...
            //    </soap:Body>
            //
            // </soap:Envelope>

            #endregion

            return(XMLNamespaces(

                       new XElement(SOAPNS.v1_2.NS.SOAPEnvelope + "Envelope",
                                    new XAttribute(XNamespace.Xmlns + "SOAP", SOAPNS.v1_2.NS.SOAPEnvelope.NamespaceName),
                                    new XAttribute(XNamespace.Xmlns + "CS", OCPPNS.OCPPv1_6_CS.NamespaceName),
                                    new XAttribute(XNamespace.Xmlns + "CP", OCPPNS.OCPPv1_6_CP.NamespaceName),

                                    new SOAPHeader(ChargeBoxIdentity,
                                                   Action,
                                                   MessageId.IsNotNullOrEmpty() ? MessageId : "uuid:" + Guid.NewGuid().ToString(),
                                                   RelatesTo,
                                                   From,
                                                   To).ToXML(),

                                    new XElement(SOAPNS.v1_2.NS.SOAPEnvelope + "Body", SOAPBody)

                                    )

                       ));
        }