public virtual HelloWCFResponse HelloWCF(HelloWCF req)
        {

            // Create request header
            String action;
            action = "http://localhost/ServiceHelloWCF/IServiceHelloWCF/HelloWCF";
            WsWsaHeader header;
            header = new WsWsaHeader(action, null, EndpointAddress, m_version.AnonymousUri, null, null);
            WsMessage request = new WsMessage(header, req, WsPrefix.None);

            // Create request serializer
            HelloWCFDataContractSerializer reqDcs;
            reqDcs = new HelloWCFDataContractSerializer("HelloWCF", "http://localhost/ServiceHelloWCF");
            request.Serializer = reqDcs;
            request.Method = "HelloWCF";


            // Send service request
            m_requestChannel.Open();
            WsMessage response = m_requestChannel.Request(request);
            m_requestChannel.Close();

            // Process response
            HelloWCFResponseDataContractSerializer respDcs;
            respDcs = new HelloWCFResponseDataContractSerializer("HelloWCFResponse", "http://localhost/ServiceHelloWCF");
            HelloWCFResponse resp;
            resp = ((HelloWCFResponse)(respDcs.ReadObject(response.Reader)));
            response.Reader.Dispose();
            response.Reader = null;
            
            return resp;
        }
Пример #2
0
        /// <summary>
        /// Helper method used to build a Dpws compliant soap response message.
        /// </summary>
        /// <param name="header">A valid response header object.</param>
        /// <param name="Dcs">A data contract serializer used to serialize the response body.</param>
        /// <param name="bodyContent">A object containing the data to serialize.</param>
        /// <returns>A byte array containing the soap reponse message.</returns>
        public static byte[] BuildSoapMessage(WsWsaHeader header, Ws.Services.Serialization.DataContractSerializer Dcs, object bodyContent)
        {
            lock (m_ThreadLock)
            {
                // Build response message
                MemoryStream soapStream;
                soapStream = new MemoryStream();
                XmlWriter xmlWriter;
                xmlWriter = XmlWriter.Create(soapStream);

                // Write start message up to body element content
                WsSoapMessageWriter.WriteSoapMessageStart(xmlWriter, WsSoapMessageWriter.Prefixes.Wsdp, null, header, null);

                // Serialize the body element
                if (bodyContent != null)
                {
                    Dcs.WriteObject(xmlWriter, bodyContent);
                }

                WsSoapMessageWriter.WriteSoapMessageEnd(xmlWriter);

                // Flush writer and build return array
                xmlWriter.Flush();
                byte[] soapBuffer = soapStream.ToArray();
                xmlWriter.Close();

                // Return soap message
                return soapBuffer;
            }
        }
        public virtual WsMessage TwoWay(WsMessage request)
        {
            // Build request object
            TwoWayRequestDataContractSerializer reqDcs;
            reqDcs = new TwoWayRequestDataContractSerializer("TwoWayRequest", "http://schemas.example.org/SimpleService");
            TwoWayRequest req;
            req = ((TwoWayRequest)(reqDcs.ReadObject(request.Reader)));
            request.Reader.Dispose();
            request.Reader = null;

            // Create response object
            // Call service operation to process request and return response.
            TwoWayResponse resp;
            resp = m_service.TwoWay(req);

            // Create response header
            WsWsaHeader respHeader = new WsWsaHeader("http://schemas.example.org/SimpleService/TwoWayResponse", request.Header.MessageID, m_version.AnonymousUri, null, null, null);
            WsMessage response = new WsMessage(respHeader, resp, WsPrefix.Wsdp);

            // Create response serializer
            TwoWayResponseDataContractSerializer respDcs;
            respDcs = new TwoWayResponseDataContractSerializer("TwoWayResponse", "http://schemas.example.org/SimpleService");
            response.Serializer = respDcs;
            return response;
        }
Пример #4
0
 public WsFaultException(WsWsaHeader header, WsFaultType faultType, String message, String detail)
 {
     this.Header = header;
     this.FaultType = faultType;
     _message = message;
     _detail = detail;
 }
        public virtual void OneWayAttachment(OneWayAttachmentRequest req)
        {

            // Create request header
            String action;
            action = "http://schemas.example.org/AttachmentService/OneWayAttachment";
            WsWsaHeader header;
            header = new WsWsaHeader(action, null, EndpointAddress, m_version.AnonymousUri, null, null);
            WsMessage request = new WsMessage(header, req, WsPrefix.None);

            // Create request serializer
            OneWayAttachmentRequestDataContractSerializer reqDcs;
            reqDcs = new OneWayAttachmentRequestDataContractSerializer("OneWayAttachmentRequest", "http://schemas.example.org/AttachmentService");
            request.Serializer = reqDcs;
            request.Method = "OneWayAttachment";


            // Indicate that this message will use Mtom encoding
            request.BodyParts = new WsMtomBodyParts();

            // Send service request
            m_requestChannel.Open();
            m_requestChannel.RequestOneWay(request);
            m_requestChannel.Close();
        }
Пример #6
0
        public virtual WsMessage GetData(WsMessage request)
        {
            // Build request object
            GetDataDataContractSerializer reqDcs;
            reqDcs = new GetDataDataContractSerializer("GetData", "http://tempuri.org/");
            reqDcs.BodyParts = request.BodyParts;
            GetData req;
            req = ((GetData)(reqDcs.ReadObject(request.Reader)));

            // Create response object
            // Call service operation to process request and return response.
            GetDataResponse resp;
            resp = m_service.GetData(req);

            // Create response header
            WsWsaHeader respHeader = new WsWsaHeader("http://tempuri.org/IDataAccessService/GetDataResponse", request.Header.MessageID, m_version.AnonymousUri, null, null, null);
            WsMessage response = new WsMessage(respHeader, resp, WsPrefix.Wsdp);

            // Create response serializer
            GetDataResponseDataContractSerializer respDcs;
            respDcs = new GetDataResponseDataContractSerializer("GetDataResponse", "http://tempuri.org/");
            response.Serializer = respDcs;

            // Indicate that message is Mtom encoded
            response.BodyParts = new WsMtomBodyParts();
            return response;
        }
Пример #7
0
        // TwoWayRequest: Accept two integer values, return their sum
        public byte[] TwoWayRequest(WsWsaHeader header, XmlReader reader)
        {
            try
            {
                // Find beginning of request
                reader.ReadStartElement("TwoWayRequest", SimpleServiceNamespaceUri);

                // Find the values to be added
                int X = Convert.ToInt32(reader.ReadElementString("X", SimpleServiceNamespaceUri));
                int Y = Convert.ToInt32(reader.ReadElementString("Y", SimpleServiceNamespaceUri));

                Log.Comment("");
                Log.Comment("X = " + X.ToString() + " Y = " + Y.ToString());
                Log.Comment(X.ToString() + " + " + Y.ToString() + " = " + ((int)(X + Y)).ToString());
                Log.Comment("");

                // Return the response
                return TwoWayResponse(header, X + Y);
            }
            catch (Exception e)
            {
                // Something went wrong 
                throw new WsFaultException(header, WsFaultType.XmlException, e.ToString());
            }
        }
Пример #8
0
        public virtual BorrowResponse Borrow(Borrow req)
        {
            // Create request header
            String action;
            action = "http://tempuri.org/IService/Borrow";
            WsWsaHeader header;
            header = new WsWsaHeader(action, null, EndpointAddress, m_version.AnonymousUri, null, null);
            WsMessage request = new WsMessage(header, req, WsPrefix.None);

            // Create request serializer
            BorrowDataContractSerializer reqDcs;
            reqDcs = new BorrowDataContractSerializer("Borrow", "http://tempuri.org/");
            request.Serializer = reqDcs;
            request.Method = "Borrow";

            // Send service request
            m_requestChannel.Open();
            WsMessage response = m_requestChannel.Request(request);
            m_requestChannel.Close();

            // Process response
            BorrowResponseDataContractSerializer respDcs;
            respDcs = new BorrowResponseDataContractSerializer("BorrowResponse", "http://tempuri.org/");
            BorrowResponse resp;
            resp = ((BorrowResponse)(respDcs.ReadObject(response.Reader)));
            response.Reader.Dispose();
            response.Reader = null;
            return resp;
        }
        public virtual TwoWayResponse TwoWay(TwoWayRequest req)
        {

            // Create request header
            String action;
            action = "http://schemas.example.org/SimpleService/TwoWay";
            WsWsaHeader header;
            header = new WsWsaHeader(action, null, EndpointAddress, m_version.AnonymousUri, null, null);
            WsMessage request = new WsMessage(header, req, WsPrefix.None);

            // Create request serializer
            TwoWayRequestDataContractSerializer reqDcs;
            reqDcs = new TwoWayRequestDataContractSerializer("TwoWayRequest", "http://schemas.example.org/SimpleService");
            request.Serializer = reqDcs;
            request.Method = "TwoWay";


            // Send service request
            m_requestChannel.Open();
            WsMessage response = m_requestChannel.Request(request);
            m_requestChannel.Close();

            // Process response
            TwoWayResponseDataContractSerializer respDcs;
            respDcs = new TwoWayResponseDataContractSerializer("TwoWayResponse", "http://schemas.example.org/SimpleService");
            TwoWayResponse resp;
            resp = ((TwoWayResponse)(respDcs.ReadObject(response.Reader)));
            return resp;
        }
        public virtual SetDataResponse SetData(SetData req)
        {

            // Create request header
            String action;
            action = "http://tempuri.org/IDataAccessService/SetData";
            WsWsaHeader header;
            header = new WsWsaHeader(action, null, EndpointAddress, m_version.AnonymousUri, null, null);
            WsMessage request = new WsMessage(header, req, WsPrefix.None);

            // Create request serializer
            SetDataDataContractSerializer reqDcs;
            reqDcs = new SetDataDataContractSerializer("SetData", "http://tempuri.org/");
            request.Serializer = reqDcs;
            request.Method = "SetData";


            // Indicate that this message will use Mtom encoding
            request.BodyParts = new WsMtomBodyParts();

            // Send service request
            m_requestChannel.Open();
            WsMessage response = m_requestChannel.Request(request);
            m_requestChannel.Close();

            // Process response
            SetDataResponseDataContractSerializer respDcs;
            respDcs = new SetDataResponseDataContractSerializer("SetDataResponse", "http://tempuri.org/");
            respDcs.BodyParts = response.BodyParts;
            SetDataResponse resp;
            resp = ((SetDataResponse)(respDcs.ReadObject(response.Reader)));
            return resp;
        }
        public virtual WsMessage HelloWCF(WsMessage request)
        {
            // Build request object
            HelloWCFDataContractSerializer reqDcs;
            reqDcs = new HelloWCFDataContractSerializer("HelloWCF", "http://localhost/ServiceHelloWCF");
            HelloWCF req;
            req = ((HelloWCF)(reqDcs.ReadObject(request.Reader)));
            request.Reader.Dispose();
            request.Reader = null;

            // Create response object
            // Call service operation to process request and return response.
            HelloWCFResponse resp;
            resp = m_service.HelloWCF(req);

            // Create response header
            WsWsaHeader respHeader = new WsWsaHeader("http://localhost/ServiceHelloWCF/IServiceHelloWCF/HelloWCFResponse", request.Header.MessageID, m_version.AnonymousUri, null, null, null);
            WsMessage response = new WsMessage(respHeader, resp, WsPrefix.Wsdp);

            // Create response serializer
            HelloWCFResponseDataContractSerializer respDcs;
            respDcs = new HelloWCFResponseDataContractSerializer("HelloWCFResponse", "http://localhost/ServiceHelloWCF");
            response.Serializer = respDcs;
            return response;
        }
Пример #12
0
        public virtual AnyCheckResponse AnyCheckRequest(AnyCheckRequest req)
        {
            // Create request header
            String action;
            action = "http://schemas.example.org/SimpleService/AnyCheckRequest";
            WsWsaHeader header;
            header = new WsWsaHeader(action, null, ServiceEndpoint, null, EndpointAddress, null);

            // Create request serializer
            AnyCheckRequestDataContractSerializer reqDcs;
            reqDcs = new AnyCheckRequestDataContractSerializer("AnyCheckRequest", "http://schemas.example.org/SimpleService");

            // Build soap request message
            byte[] soapBuffer = SoapMessageBuilder.BuildSoapMessage(header, reqDcs, req);

            // Send service request
            DpwsHttpClient httpClient;
            httpClient = new DpwsHttpClient();
            DpwsSoapResponse response;
            response = httpClient.SendRequest(soapBuffer, ServiceEndpoint, false, false);

            // Process response
            AnyCheckResponseDataContractSerializer respDcs;
            respDcs = new AnyCheckResponseDataContractSerializer("AnyCheckResponse", "http://schemas.example.org/SimpleService");
            AnyCheckResponse resp;
            resp = ((AnyCheckResponse)(respDcs.ReadObject(response.Reader)));
            return resp;
        }
Пример #13
0
        public static XmlReader ParseSoapMessage(byte[] soapMessage, out WsWsaHeader header)
        {
            MemoryStream requestStream = new MemoryStream(soapMessage);
            XmlReader reader = XmlReader.Create(requestStream);
            header = new WsWsaHeader();

            try
            {
                reader.ReadStartElement("Envelope", WsWellKnownUri.SoapNamespaceUri);
#if DEBUG
                int depth = reader.Depth;
#endif
                header.ParseHeader(reader);
#if DEBUG
                Microsoft.SPOT.Debug.Assert(XmlReaderHelper.HasReadCompleteNode(depth, reader));
#endif
                reader.ReadStartElement("Body", WsWellKnownUri.SoapNamespaceUri);

            }
            catch (XmlException e)
            {
                reader.Close();
                throw new WsFaultException(header, WsFaultType.XmlException, e.ToString());
            }

            return reader;
        }
Пример #14
0
 public WsMessage( WsWsaHeader header, object body, WsPrefix prefixes, WsXmlNamespaces namespaces, WsAppSequence appSequence)
 {
     this.Header      = header;
     this.Body        = body;
     this.Prefixes    = prefixes;
     this.Namespaces  = namespaces;
     this.AppSequence = appSequence;
 }
Пример #15
0
        public byte[] TwoWayResponse(WsWsaHeader header, int sum)
        {
            MemoryStream soapStream = new MemoryStream();
            XmlWriter xmlWriter = XmlWriter.Create(soapStream);

            // Write processing instructions and root element
            xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
            xmlWriter.WriteStartElement("soap", "Envelope", 
                "http://www.w3.org/2003/05/soap-envelope");

            // Write namespaces
            xmlWriter.WriteAttributeString("xmlns", "wsdp", null, 
                Device.Namespaces.GetNamespace("wsdp"));
            xmlWriter.WriteAttributeString("xmlns", "wsd", null, 
                Device.Namespaces.GetNamespace("wsd"));
            xmlWriter.WriteAttributeString("xmlns", "wsa", null, 
                Device.Namespaces.GetNamespace("wsa"));
            xmlWriter.WriteAttributeString("xmlns", "sim", null, 
                TypeNamespaces.GetNamespace("sim"));

            // Write header
            xmlWriter.WriteStartElement("soap", "Header", null);
            xmlWriter.WriteStartElement("wsa", "To", null);
            xmlWriter.WriteString(header.From);
            xmlWriter.WriteEndElement();
            xmlWriter.WriteStartElement("wsa", "Action", null);
            xmlWriter.WriteString("http://schemas.example.org/SimpleService/TwoWayResponse");
            xmlWriter.WriteEndElement();
            xmlWriter.WriteStartElement("wsa", "RelatesTo", null);
            xmlWriter.WriteString(header.MessageID);
            xmlWriter.WriteEndElement(); // End RelatesTo
            xmlWriter.WriteStartElement("wsa", "MessageID", null);
            xmlWriter.WriteString("urn:uuid:" + Device.GetUuid());
            xmlWriter.WriteEndElement(); // End MessageID
            xmlWriter.WriteEndElement(); // End Header

            // write body
            xmlWriter.WriteStartElement("soap", "Body", null);
            xmlWriter.WriteStartElement("sim", "TwoWayResponse", null);
            xmlWriter.WriteStartElement("sim", "Sum", null);
            xmlWriter.WriteString(sum.ToString());
            xmlWriter.WriteEndElement(); // End Sun
            xmlWriter.WriteEndElement(); // End TwoWayResponse
            xmlWriter.WriteEndElement(); // End Body

            xmlWriter.WriteEndElement();

            // Create return buffer and close writer
            xmlWriter.Flush();
            byte[] soapBuffer = soapStream.ToArray();
            xmlWriter.Close();

            return soapBuffer;
        }
Пример #16
0
        public byte[] MyOneWayOperation(WsWsaHeader header, XmlReader reader)
        {
            reader.ReadStartElement("MyOneWayRequest", this.ServiceNamespace.NamespaceURI);

            // Extract parameter A from SOAP message body
            string str = reader.ReadElementString("A", this.ServiceNamespace.NamespaceURI);
            int a = Convert.ToInt32(str);

            Debug.Print("MyOneWayOperation with A=" + a + " executed.");
            return null; // No response it is a one-way operation
        }
Пример #17
0
 public void FireSimpleEvent(int a)
 {
     DpwsWseEventSource eventSource = this.EventSources["SimpleEvent"];
     WsWsaHeader header = new WsWsaHeader(c_namespaceUri + "/SimpleEvent", null, null, null, null, null);
     Device.SubscriptionManager.FireEvent(this, // hosted service
                                          eventSource,
                                          header,
                                          BuildSimpleEventMessageBody(a)
                                          );
     Debug.Print("Simple event was fired with param a=" + a + ".");
 }
Пример #18
0
        public static WsMessage CreateOneWayResponse()
        {
            if (s_OneWayResponse == null)
            {
                WsWsaHeader header = new WsWsaHeader(null, null, null, null, null, null);

                header.IsOneWayResponse = true;

                s_OneWayResponse = new WsMessage(header, null, WsPrefix.None);
            }

            return s_OneWayResponse;
        }
        private byte[] SimpleEvent(WsWsaHeader header, XmlReader reader)
        {
            reader.ReadStartElement("SimpleEvent", c_namespaceUri);

            // Extract parameter Quotient from SOAP message body
            string str = reader.ReadElementString("A", c_namespaceUri);
            int a = Convert.ToInt32(str);
            Debug.Print("Simple event notification was received with A=" +
                        a + ".");

            // Event handlers provide no response (but do not return null).
            return new byte[0];
        }
        public virtual Byte[] OneWay(WsWsaHeader header, XmlReader reader)
        {
            // Build request object
            OneWayDataContractSerializer reqDcs;
            reqDcs = new OneWayDataContractSerializer("OneWay", "http://schemas.example.org/SimpleService");
            OneWay req;
            req = ((OneWay)(reqDcs.ReadObject(reader)));

            // Call service operation to process request.
            m_service.OneWay(req);

            // Return null response for oneway messages
            return null;
        }
Пример #21
0
        public byte[] OneWay(WsWsaHeader header, WsXmlDocument envelope)
        {
            WsXmlNode tempNode;
            WsFault fault = new WsFault();

            if ((tempNode = envelope.SelectSingleNode("Body/OneWay/Param", false)) == null)
                return fault.RaiseFault(header, WsExceptionFaultType.XmlException, 
                    "Body/OneWay is missing.");
            int number = Convert.ToInt32(tempNode.Value);
            Debug.Print("");
            Debug.Print("Integer = " + tempNode.Value);
            Debug.Print("");
            byte[] response = new byte[0];
            return response;
        }
Пример #22
0
        // This method is called by the timer delegate periodically to send events
        public void SendEvent(Object stateInfo)
        {
            if (rentryFlag == true)     // prevent this method from running concurrently with itself
                return;
            rentryFlag = true;

            // Fire SimpleEvent
            try
            {
                DpwsWseEventSource eventSource = m_hostedService.EventSources["SimpleEvent"];
                WsWsaHeader header = new WsWsaHeader("http://schemas.example.org/EventingService/SimpleEvent", null, null, null, null, null);

                WsMessage msg = new WsMessage(header, null, WsPrefix.Wse);

                msg.Body = System.Text.UTF8Encoding.UTF8.GetBytes(BuildSimpleEventMessage(m_hostedService));

                Device.SubscriptionManager.FireEvent(m_hostedService, eventSource, msg );
            }
            catch
            {
                //Log.Comment("");
                //Log.Comment("SimpleEvent FireEvent failed: " + e.Message);
                //Log.Comment("");
                rentryFlag = false;
            }

            // Fire IntegerEvent
            try
            {
                DpwsWseEventSource eventSource = m_hostedService.EventSources["IntegerEvent"];
                WsWsaHeader header = new WsWsaHeader("http://schemas.example.org/EventingService/IntegerEvent", null, null, null, null, null);

                WsMessage msg = new WsMessage(header, null, WsPrefix.Wse);

                msg.Body = System.Text.UTF8Encoding.UTF8.GetBytes(BuildIntegerEventMessage(m_hostedService));
                                
                Device.SubscriptionManager.FireEvent(m_hostedService, eventSource, msg);
            }
            catch
            {
                //Log.Comment("");
                //Log.Comment("IntegerEvent FireEvent failed: " + e.Message);
                //Log.Comment("");
                rentryFlag = false;
            }

            rentryFlag = false;
        }
        public byte[] BuildMyTwoWayResponse(WsWsaHeader header, int quotient)
        {
            MemoryStream soapStream = new MemoryStream();
            XmlWriter xmlWriter = XmlWriter.Create(soapStream);

            // Write processing instructions and root element
            xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
            xmlWriter.WriteStartElement("soap", "Envelope", WsWellKnownUri.SoapNamespaceUri);

            // Write namespaces
            xmlWriter.WriteAttributeString("xmlns", "wsa", null, WsWellKnownUri.WsaNamespaceUri);
            xmlWriter.WriteAttributeString("xmlns", "twoWay", null, c_namespaceUri);

            // Write header
            xmlWriter.WriteStartElement("soap", "Header", null);
            xmlWriter.WriteStartElement("wsa", "To", null);
            xmlWriter.WriteString(header.From.Address.AbsoluteUri);
            xmlWriter.WriteEndElement();
            xmlWriter.WriteStartElement("wsa", "Action", null);
            xmlWriter.WriteString(c_namespaceUri + "/TwoWayOperationResponse");
            xmlWriter.WriteEndElement();
            xmlWriter.WriteStartElement("wsa", "RelatesTo", null);
            xmlWriter.WriteString(header.MessageID);
            xmlWriter.WriteEndElement(); // End RelatesTo
            xmlWriter.WriteStartElement("wsa", "MessageID", null);
            xmlWriter.WriteString("urn:uuid:" + Guid.NewGuid());
            xmlWriter.WriteEndElement(); // End MessageID
            xmlWriter.WriteEndElement(); // End Header

            // write body
            xmlWriter.WriteStartElement("soap", "Body", null);
            xmlWriter.WriteStartElement("twoWay", "MyTwoWayResponse", null);
            xmlWriter.WriteStartElement("twoWay", "Quotient", null);
            xmlWriter.WriteString(quotient.ToString());
            xmlWriter.WriteEndElement(); // End Quotient
            xmlWriter.WriteEndElement(); // End MyTwoWayResponse
            xmlWriter.WriteEndElement(); // End Body

            xmlWriter.WriteEndElement();

            // Create return buffer and close writer
            xmlWriter.Flush();
            byte[] soapBuffer = soapStream.ToArray();
            xmlWriter.Close();

            return soapBuffer;
        }
Пример #24
0
        /// <summary>
        /// Helper method used by a hosted service to generate an event messages body elements.
        /// </summary>
        /// <param name="header">A valid response header object.</param>
        /// <param name="Dcs">A data contract serializer used to serialize the response body.</param>
        /// <param name="bodyContent">A object containing the data to serialize.</param>
        /// <returns>A byte array containg the serialized body elements of event message.</returns>
        public static byte[] BuildEventBody(WsWsaHeader header, Ws.Services.Serialization.DataContractSerializer Dcs, object bodyContent)
        {
            // Create an XmlWriter
            MemoryStream soapStream;
            soapStream = new MemoryStream();
            XmlWriter xmlWriter = XmlWriter.Create(soapStream);

            // Create Xml body element
            Dcs.WriteObject(xmlWriter, bodyContent);

            // Flush writer and build message buffer
            xmlWriter.Flush();
            byte[] soapBuffer = soapStream.ToArray();
            xmlWriter.Close();

            // return xml message buffer
            return soapBuffer;
        }
Пример #25
0
        public byte[] TwoWayRequest(WsWsaHeader header, WsXmlDocument envelope)
        {
            WsXmlNode tempNode;
            WsFault fault = new WsFault();

            if ((tempNode = envelope.SelectSingleNode("Body/TwoWayRequest/X", false)) == null)
                return fault.RaiseFault(header, WsExceptionFaultType.XmlException, 
                    "Body/TwoWay X value is missing.");
            int X = Convert.ToInt32(tempNode.Value);
            if ((tempNode = envelope.SelectSingleNode("Body/TwoWayRequest/Y", false)) == null)
                return fault.RaiseFault(header, WsExceptionFaultType.XmlException, 
                    "Body/TwoWay Y value is missing.");
            int Y = Convert.ToInt32(tempNode.Value);
            Debug.Print("");
            Debug.Print("X = " + X.ToString() + " Y = " + Y.ToString());
            Debug.Print(X.ToString() + " + " + Y.ToString() + " = " + ((int)(X + Y)).ToString());
            Debug.Print("");

            return TwoWayResponse(header, X + Y);
        }
Пример #26
0
        /// <summary>
        /// Create an instance of a SubscriptionEndEvent arguments object.
        /// </summary>
        internal SubscriptionEndEventArgs(WsWsaHeader header, XmlReader reader)
        {
            // Retrieve the Identifier

            this.Identifier = header.Any.GetNodeValue("Identifier", WsWellKnownUri.WseNamespaceUri);

            reader.ReadStartElement("SubscriptionEnd", WsWellKnownUri.WseNamespaceUri);

            if (reader.IsStartElement("SubscriptionManager", WsWellKnownUri.WseNamespaceUri))
            {
                this.SubscriptionManager = new WsWsaEndpointRef(reader);
            }

            this.SubscriptionID = this.SubscriptionManager.RefParameters.GetNodeValue("Identifier", WsWellKnownUri.WseNamespaceUri);

            if (this.SubscriptionID == null || this.Identifier == null) // both need to be there
            {
                throw new XmlException();
            }
        }
        public virtual void IntegerEvent(IntegerEventRequest eventReq)
        {

            // Create temp event source object, set the event action and create the event header
            DpwsWseEventSource eventSource;
            eventSource = EventSources["IntegerEvent"];
            String action;
            action = "http://schemas.example.org/EventingService/IntegerEvent";
            WsWsaHeader header;
            header = new WsWsaHeader(action, null, null, null, null, null);
            WsMessage msg = new WsMessage(header, eventReq, WsPrefix.Wse);

            // Create event serializer and write the event object
            IntegerEventRequestDataContractSerializer eventDcs;
            eventDcs = new IntegerEventRequestDataContractSerializer("IntegerEventRequest", "http://schemas.example.org/EventingService");
            msg.Serializer = eventDcs;

            // Fire event
            Dpws.Device.Device.SubscriptionManager.FireEvent(this, eventSource, msg);
        }
Пример #28
0
        public virtual void OneWay(OneWay req)
        {
            // Create request header
            String action;
            action = "http://schemas.example.org/SimpleService/OneWay";
            WsWsaHeader header;
            header = new WsWsaHeader(action, null, ServiceEndpoint, null, EndpointAddress, null);

            // Create request serializer
            OneWayDataContractSerializer reqDcs;
            reqDcs = new OneWayDataContractSerializer("OneWay", "http://schemas.example.org/SimpleService");

            // Build soap request message
            byte[] soapBuffer = SoapMessageBuilder.BuildSoapMessage(header, reqDcs, req);

            // Send service request
            DpwsHttpClient httpClient;
            httpClient = new DpwsHttpClient();
            DpwsSoapResponse response;
            response = httpClient.SendRequest(soapBuffer, ServiceEndpoint, true, false);
        }
Пример #29
0
        public virtual void OneWay(OneWayRequest req)
        {

            // Create request header
            String action;
            action = "http://schemas.example.org/SimpleService/OneWay";
            WsWsaHeader header;
            header = new WsWsaHeader(action, null, EndpointAddress, m_version.AnonymousUri, null, null);
            WsMessage request = new WsMessage(header, req, WsPrefix.None);

            // Create request serializer
            OneWayRequestDataContractSerializer reqDcs;
            reqDcs = new OneWayRequestDataContractSerializer("OneWayRequest", "http://schemas.example.org/SimpleService");
            request.Serializer = reqDcs;
            request.Method = "OneWay";


            // Send service request
            m_requestChannel.Open();
            m_requestChannel.RequestOneWay(request);
            m_requestChannel.Close();
        }
Пример #30
0
        public byte[] OneWay(WsWsaHeader header, XmlReader reader)
        {
             try
            {
                // Find beginning of request
                reader.ReadStartElement("OneWay", SimpleServiceNamespaceUri);

                // Find the integer value
                int number = Convert.ToInt32(reader.ReadElementString("Param", SimpleServiceNamespaceUri));

                Log.Comment("");
                Log.Comment("Integer = " + number.ToString());
                Log.Comment("");

                return new byte[0];     // Empty response
            }
            catch (Exception e)
            {
                // Something went wrong
                throw new WsFaultException(header, WsFaultType.XmlException, e.ToString());
            }
        }