public void WhenASOAPEnvelopeWithAHeaderBlockFromAnObjectWithAnXMLRootAttributeIsBuilt_WithAGivenXMLElementNameAndNamespace()
        {
            var obj = new XmlObjectWithRootAttribute
            {
                MyProperty = 2
            };

            this.soapEnvelope = SoapBuilder.CreateSoap12Envelope()
                                .WithHeader.AddBlock(obj, "NewElementName", "http://new.root.namespace")
                                .Build()
                                .ToString();

            this.xmlTester.ArrangeActualXml(this.soapEnvelope);

            const string expectedXml =
                @"<env:Envelope xmlns:env=""http://www.w3.org/2003/05/soap-envelope"">
  <env:Header>
    <NewElementName xmlns=""http://new.root.namespace"">
        <MyProperty>2</MyProperty>
    </NewElementName>
  </env:Header>
</env:Envelope>";

            this.xmlTester.ArrangeExpectedXml(expectedXml);
        }
Esempio n. 2
0
        public byte[] BuildProbeMatches(string[] scopes, bool onvif20, string[] xAddrs, string relateTo)
        {
            Proxies.WSDiscovery.ProbeMatchesType probeMatches = new Proxies.WSDiscovery.ProbeMatchesType();

            probeMatches.ProbeMatch = new Proxies.WSDiscovery.ProbeMatchType[1];
            Proxies.WSDiscovery.ProbeMatchType probeMatch = new Proxies.WSDiscovery.ProbeMatchType();

            // Scopes
            probeMatch.Scopes = BuildScopes(scopes, null);

            // Types
            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();

            probeMatch.Types = BuildTypes(onvif20, ref namespaces);

            // EndpointReference
            probeMatch.EndpointReference = BuildEndpointReference();

            // XAddrs
            probeMatch.XAddrs = BuildXAddrs(xAddrs);

            // MetadataVersion
            probeMatch.MetadataVersion = 0;

            probeMatches.ProbeMatch[0] = probeMatch;

            DiscoveryHeaderBuilder header = new DiscoveryHeaderBuilder();

            header.OrigingMessageId = relateTo;

            byte[] msg = SoapBuilder.BuildMessage(probeMatches, Encoding.UTF8, header, namespaces);

            return(msg);
        }
Esempio n. 3
0
        public void WhenASOAPEnvelopeWithABodyEntryFromAnObjectWithAnXMLTypeAttributeIsBuilt()
        {
            var obj = new XmlObjectWithTypeAttribute
            {
                MyProperty = 2
            };

            this.soapEnvelope = SoapBuilder.CreateSoap11Envelope()
                                .WithBody.AddEntry(obj)
                                .Build()
                                .ToString();

            this.xmlTester.ArrangeActualXml(this.soapEnvelope);

            var expectedXml =
                @"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/"">
  <env:Body>
    <XmlObjectWithTypeAttribute xmlns=""http://type.attribute"">
        <MyProperty>2</MyProperty>
    </XmlObjectWithTypeAttribute>
  </env:Body>
</env:Envelope>";

            this.xmlTester.ArrangeExpectedXml(expectedXml);
        }
Esempio n. 4
0
        public void WhenASOAPEnvelopeWithABodyEntryFromAnObjectWithAnXMLRootAttributeIsBuilt_WithAGivenXMLElementNameAndNamespace()
        {
            var obj = new XmlObjectWithRootAttribute
            {
                MyProperty = 2
            };

            this.soapEnvelope = SoapBuilder.CreateSoap11Envelope()
                                .WithBody.AddEntry(obj, "NewElementName", "http://new.root.namespace")
                                .Build()
                                .ToString();

            this.xmlTester.ArrangeActualXml(this.soapEnvelope);

            var expectedXml =
                @"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/"">
  <env:Body>
    <NewElementName xmlns=""http://new.root.namespace"">
        <MyProperty>2</MyProperty>
    </NewElementName>
  </env:Body>
</env:Envelope>";

            this.xmlTester.ArrangeExpectedXml(expectedXml);
        }
Esempio n. 5
0
        public void WhenASOAPEnvelopeWithAFaultIsBuilt()
        {
            this.soapEnvelope = SoapBuilder.CreateSoap11Envelope()
                                .WithBody.SetFault(Soap11FaultCode.Client, "oops", "it was me!", new XContainer[] { XElement.Parse("<myDetail1>detail 1</myDetail1>"), XElement.Parse("<myDetail2>detail 2</myDetail2>") })
                                .Build()
                                .ToString();

            this.xmlTester.ArrangeActualXml(this.soapEnvelope);

            var expectedXml =
                @"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/"">
  <env:Body>
    <env:Fault>
      <faultcode>env:Client</faultcode>
      <faultstring>oops</faultstring>
      <faultactor>it was me!</faultactor>
      <detail>
        <myDetail1>detail 1</myDetail1>
        <myDetail2>detail 2</myDetail2>
      </detail>
    </env:Fault>
    </env:Body>
</env:Envelope>";

            this.xmlTester.ArrangeExpectedXml(expectedXml);
        }
Esempio n. 6
0
        public void WhenASOAPEnvelopeWithAHeaderBlockFromAnXMLStringIsBuilt()
        {
            var obj = new XmlObjectWithRootAttribute
            {
                MyProperty = 2
            };

            this.soapEnvelope = SoapBuilder.CreateSoap11Envelope()
                                .WithHeader.AddBlock(ObjectXmlSerialiser.SerialiseObject(obj, null, null))
                                .Build()
                                .ToString();

            this.xmlTester.ArrangeActualXml(this.soapEnvelope);

            const string expectedXml =
                @"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/"">
  <env:Header>
    <XmlObjectWithRootAttribute xmlns=""http://root.attribute"">
        <MyProperty>2</MyProperty>
    </XmlObjectWithRootAttribute>
  </env:Header>
</env:Envelope>";

            this.xmlTester.ArrangeExpectedXml(expectedXml);
        }
Esempio n. 7
0
        public byte[] BuildHello(
            string[] scopes, string types, XmlQualifiedName[] typesNamespaces, string[] xAddrs, uint metadataVersion)
        {
            Proxies.WSDiscovery.HelloType hello = new Proxies.WSDiscovery.HelloType();

            // Scopes
            hello.Scopes = BuildScopes(scopes, null);

            // Types
            hello.Types = types;

            // EndpointReference
            hello.EndpointReference = BuildEndpointReference();

            // XAddrs
            hello.XAddrs = BuildXAddrs(xAddrs);

            // MetadataVersion
            hello.MetadataVersion = metadataVersion;

            byte[] msg = SoapBuilder.BuildMessage(
                hello, Encoding.UTF8, new DiscoveryHeaderBuilder(), new XmlSerializerNamespaces(typesNamespaces));

            return(msg);
        }
Esempio n. 8
0
 private void OnDataReceived(byte[] data, IPEndPoint sender)
 {
     try
     {
         SoapMessage <WSD.ProbeType> probe = SoapBuilder.ParseMessage <WSD.ProbeType>(data, null);
         if (OnProbeReceived != null)
         {
             DiscoverProbeEventArgs args = new DiscoverProbeEventArgs();
             args.Sender = sender;
             args.Probe  = probe.Object;
             OnProbeReceived(this, args);
             if (args.Response != null)
             {
                 XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
                 namespaces.Add("dn", DiscoveryUtils.ONVIF_NETWORK_WSDL_URL);
                 DiscoveryHeaderBuilder header = new DiscoveryHeaderBuilder();
                 header.OrigingMessageId = GetMessageId(probe.Header);
                 byte[] response = SoapBuilder.BuildMessage(args.Response, Encoding.UTF8, header, namespaces);
                 Send(response);
             }
         }
     }
     catch
     {
     }
 }
        public void WhenASOAPEnvelopeWithABodyEntryFromAnObjectWithNoXMLAttributeIsBuilt()
        {
            var obj = new XmlObjectWithNoAttribute
            {
                MyProperty = 2
            };

            this.soapEnvelope = SoapBuilder.CreateSoap12Envelope()
                                .WithBody.AddEntry(obj)
                                .Build()
                                .ToString();

            this.xmlTester.ArrangeActualXml(this.soapEnvelope);

            const string expectedXml =
                @"<env:Envelope xmlns:env=""http://www.w3.org/2003/05/soap-envelope"">
  <env:Body>
    <XmlObjectWithNoAttribute>
        <MyProperty>2</MyProperty>
    </XmlObjectWithNoAttribute>
  </env:Body>
</env:Envelope>";

            this.xmlTester.ArrangeExpectedXml(expectedXml);
        }
        public void WhenASOAPEnvelopeWithAHeaderBlockFromAnObjectWithAnXMLTypeAttributeIsBuilt()
        {
            var obj = new XmlObjectWithTypeAttribute
            {
                MyProperty = 2
            };

            this.soapEnvelope = SoapBuilder.CreateSoap12Envelope()
                                .WithHeader.AddBlock(obj)
                                .Build()
                                .ToString();

            this.xmlTester.ArrangeActualXml(this.soapEnvelope);

            const string expectedXml =
                @"<env:Envelope xmlns:env=""http://www.w3.org/2003/05/soap-envelope"">
  <env:Header>
    <XmlObjectWithTypeAttribute xmlns=""http://type.attribute"">
        <MyProperty>2</MyProperty>
    </XmlObjectWithTypeAttribute>
  </env:Header>
</env:Envelope>";

            this.xmlTester.ArrangeExpectedXml(expectedXml);
        }
        public void WhenASOAPEnvelopeWithAHeaderBlockFromAnXContainerIsBuilt()
        {
            var obj = new XmlObjectWithRootAttribute
            {
                MyProperty = 2
            };

            this.soapEnvelope = SoapBuilder.CreateSoap12Envelope()
                                .WithHeader.AddBlock(XElement.Parse(ObjectXmlSerialiser.SerialiseObject(obj, null, null)))
                                .Build()
                                .ToString();

            this.xmlTester.ArrangeActualXml(this.soapEnvelope);

            const string expectedXml =
                @"<env:Envelope xmlns:env=""http://www.w3.org/2003/05/soap-envelope"">
  <env:Header>
    <XmlObjectWithRootAttribute xmlns=""http://root.attribute"">
        <MyProperty>2</MyProperty>
    </XmlObjectWithRootAttribute>
  </env:Header>
</env:Envelope>";

            this.xmlTester.ArrangeExpectedXml(expectedXml);
        }
Esempio n. 12
0
        private static void ParseDeviceInfo(Conversation conversation, Device device)
        {
            if (null == device)
            {
                return;
            }

            int pairNumber;

            if (!DeviceInfoExists(conversation, out pairNumber))
            {
                return;
            }

            var pair = conversation.GetMessages(ContentType.Http)[pairNumber];

            try
            {
                var message =
                    SoapBuilder.ParseMessage <GetDeviceInformationResponse>(
                        new StringReader(pair.GetResponse <HttpMessage>().GetXmlString()), null);

                DeviceInformation deviceInfo = DeviceInformation.Create(message);

                device.SetInformation(deviceInfo);
            }
            catch (Exception e)
            {
                Logger.WriteLine(String.Format(e.Message));
            }
        }
Esempio n. 13
0
 public void GivenAValidRequestForTheSOAP11Service()
 {
     this.request = SoapBuilder.CreateSoap11Envelope()
                    .WithHeader.AddAction(TestCaseSoapActions.MySoap11ServiceTestAction)
                    .WithBody.AddEntry("<TestAction>Hello</TestAction>")
                    .Build().ToString();
     Logger.Log("Request: " + this.request);
 }
Esempio n. 14
0
 public InvoiceService(InvoiceRepository repository, InvoiceClient client,
                       RequestManager requestManager, SoapBuilder soapBuilder, Serializer serializer,
                       Zipper zipper
                       )
 {
     _repository     = repository;
     _client         = client;
     _requestManager = requestManager;
     _soapBuilder    = soapBuilder;
     _serializer     = serializer;
     _zipper         = zipper;
 }
        public void WhenTheBodyIsSpecifiedTwice_DirectlyAsABodyEntryAndThenAsAFault()
        {
            base.ExpectedException.MessageShouldContainText = "Cannot set a fault because the body already has an entry";

            Try(() =>
            {
                this.soapEnvelope = SoapBuilder.CreateSoap12Envelope()
                                    .WithBody.AddEntry("<a>body entry 1</a>")
                                    .WithBody.SetFault(Soap12FaultCode.Sender, "bummer1 - this will throw an exception")
                                    .Build()
                                    .ToString();
            });
        }
        public void WhenTheBodyIsSpecifiedTwiceAsAFault()
        {
            base.ExpectedException.MessageShouldContainText = "Cannot set a fault because the body already has an entry";

            Try(() =>
            {
                this.soapEnvelope = SoapBuilder.CreateSoap12Envelope()
                                    .WithBody.SetFault(Soap12FaultCode.Sender, "bummer1")
                                    .WithBody.SetFault(Soap12FaultCode.Sender, "bummer2")
                                    .Build()
                                    .ToString();
            });
        }
        public void WhenTheBodyIsSpecifiedTwiceAsAFaultAndThenDirectlyAsABodyEntry()
        {
            base.ExpectedException.MessageShouldContainText = "Cannot add the body entry because a fault has already been specified";

            Try(() =>
            {
                this.soapEnvelope = SoapBuilder.CreateSoap12Envelope()
                                    .WithBody.SetFault(Soap12FaultCode.Sender, "bummer1")
                                    .WithBody.AddEntry("<b>this should throw an exception</b>")
                                    .Build()
                                    .ToString();
            });
        }
Esempio n. 18
0
        static void Main(string[] args)
        {
            var encoding       = Encoding.UTF8;
            var requestManager = new RequestManager();
            var repo           = new InvoiceRepository();
            var builder        = new SoapBuilder(encoding);
            var serializer     = new Serializer();
            var zipper         = new Zipper();

            var client  = new InvoiceClient(requestManager);
            var service = new InvoiceService(repo, client, requestManager, builder, serializer, zipper);

            var result = service.SendBill("12345abc");
            //Console.WriteLine(result);
            //Console.Read();
        }
Esempio n. 19
0
        public void SendHello()
        {
            WSD.HelloType           hello      = new WSD.HelloType();
            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();

            namespaces.Add("dn", DiscoveryUtils.ONVIF_NETWORK_WSDL_URL);
            hello.EndpointReference               = new WSD.EndpointReferenceType();
            hello.EndpointReference.Address       = new WSD.AttributedURI();
            hello.EndpointReference.Address.Value = _uuid;
            hello.Types       = "dn:NetworkVideoTransmitter";
            hello.Scopes      = new WSD.ScopesType();
            hello.Scopes.Text = _scopes;
            hello.XAddrs      = ServiceAddress;

            byte[] data = SoapBuilder.BuildMessage(hello, Encoding.UTF8, new DiscoveryHeaderBuilder(), namespaces);
            Send(data);
        }
Esempio n. 20
0
        public void WhenASOAPEnvelopeWithABodyIsBuilt()
        {
            this.soapEnvelope = SoapBuilder.CreateSoap11Envelope()
                                .WithBody.AddEntry("<a>hello from the body</a>")
                                .Build()
                                .ToString();

            this.xmlTester.ArrangeActualXml(this.soapEnvelope);

            var expectedXml =
                @"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/"">
  <env:Body>
    <a>hello from the body</a>
  </env:Body>
</env:Envelope>";

            this.xmlTester.ArrangeExpectedXml(expectedXml);
        }
Esempio n. 21
0
        static void Main(string[] args)
        {
            ProbeType probe = new ProbeType();

            probe.Types          = "dn:VideoTransmitter";
            probe.Scopes         = new ScopesType();
            probe.Scopes.MatchBy = "trololo";

            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();

            namespaces.Add("dn", "http://www.onvif.org/ver10/network/wsdl");
            DiscoveryHeaderBuilder header = new DiscoveryHeaderBuilder();

            byte[] soap = SoapBuilder.BuildMessage(probe, Encoding.UTF8, header, namespaces);

            ICollection <XmlElement> headers;
            ProbeType parsed = SoapBuilder.ParseMessage <ProbeType>(soap, GetSchemas(), out headers);
        }
        public void WhenASOAPEnvelopeWithAHeaderIsBuilt()
        {
            this.soapEnvelope = SoapBuilder.CreateSoap12Envelope()
                                .WithHeader.AddAction("myActionOhYeah!")
                                .Build()
                                .ToString();

            this.xmlTester.ArrangeActualXml(this.soapEnvelope);

            const string expectedXml =
                @"<env:Envelope xmlns:env=""http://www.w3.org/2003/05/soap-envelope"">
  <env:Header>
    <wsa:Action xmlns:wsa=""http://www.w3.org/2005/08/addressing"">myActionOhYeah!</wsa:Action>
  </env:Header>
</env:Envelope>";

            this.xmlTester.ArrangeExpectedXml(expectedXml);
        }
Esempio n. 23
0
        public void GivenTheSOAPServiceWillRespondWithASuccessfulPayload()
        {
            this.expectedResponse = SoapBuilder.CreateSoap11Envelope()
                                    .WithBody.AddEntry("<TestActionResponse>World!</TestActionResponse>")
                                    .Build().ToString();
            Logger.Log("Expected response: " + this.expectedResponse);

            this.nancySoapAdapter.RegisterSoapActionHandler(
                TestCaseRoutes.MySoap11Service,
                TestCaseSoapActions.MySoap11ServiceTestAction,
                (request, _) =>
            {
                Logger.Log($"Fake service for action '{TestCaseSoapActions.MySoap11ServiceTestAction}' is executing...");
                Logger.Log("Request message was: " + request.GetRequestBodyAsString());

                return(Soap11NancyResponseFactory.Create(this.expectedResponse, HttpStatusCode.OK));
            });
        }
        public void WhenASOAPEnvelopeWithABodyIsBuilt()
        {
            this.soapEnvelope = SoapBuilder.CreateSoap12Envelope()
                                .WithBody.AddEntry("<a>hello from the body</a>")
                                .Build()
                                .ToString();

            this.xmlTester.ArrangeActualXml(this.soapEnvelope);

            const string expectedXml =
                @"<env:Envelope xmlns:env=""http://www.w3.org/2003/05/soap-envelope"">
  <env:Body>
    <a>hello from the body</a>
  </env:Body>
</env:Envelope>";

            this.xmlTester.ArrangeExpectedXml(expectedXml);
        }
        public void WhenASOAPEnvelopeWithACustomisedSoapEncodingIsBuilt()
        {
            this.soapEnvelope = SoapBuilder.CreateSoap12Envelope()
                                .WithBody.SetCustomSoapEncoding("custom soap encoding namespace!!")
                                .WithBody.AddEntry("<a>hello</a>")
                                .Build()
                                .ToString();

            this.xmlTester.ArrangeActualXml(this.soapEnvelope);

            const string expectedXml =
                @"<env:Envelope xmlns:env=""http://www.w3.org/2003/05/soap-envelope"">
  <env:Body env:soapEncoding=""custom soap encoding namespace!!"">
    <a>hello</a>
  </env:Body>
</env:Envelope>";

            this.xmlTester.ArrangeExpectedXml(expectedXml);
        }
Esempio n. 26
0
        public void WhenASOAPEnvelopeWithTheStandardSoapEncodingIsBuilt()
        {
            this.soapEnvelope = SoapBuilder.CreateSoap12Envelope()
                                .WithBody.SetStandardSoapEncoding()
                                .WithBody.AddEntry("<a>hello</a>")
                                .Build()
                                .ToString();

            this.xmlTester.ArrangeActualXml(this.soapEnvelope);

            var expectedXml =
                @"<env:Envelope xmlns:env=""http://www.w3.org/2003/05/soap-envelope"">
  <env:Body env:soapEncoding=""http://www.w3.org/2003/05/soap-encoding"">
    <a>hello</a>
  </env:Body>
</env:Envelope>";

            this.xmlTester.ArrangeExpectedXml(expectedXml);
        }
 /// <summary>
 /// Data receiving.
 /// </summary>
 /// <param name="data"></param>
 protected override void  OnMessageReceived(byte[] data)
 {
     try
     {
         _rawData = data;
         SoapMessage <Notify> notify = SoapBuilder.ParseMessage <Notify>(data, null);
         if (OnNotify != null)
         {
             OnNotify(notify, data);
         }
     }
     catch (Exception ex)
     {
         if (OnError != null)
         {
             OnError(ex);
         }
     }
 }
Esempio n. 28
0
        public void WhenASOAPEnvelopeWithTheStandardSoapEncodingIsBuilt()
        {
            this.soapEnvelope = SoapBuilder.CreateSoap11Envelope()
                                .WithBody.SetStandardSoapEncoding()
                                .WithBody.AddEntry("<a>hello</a>")
                                .Build()
                                .ToString();

            this.xmlTester.ArrangeActualXml(this.soapEnvelope);

            const string expectedXml =
                @"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/"">
  <env:Body env:soapEncoding=""http://schemas.xmlsoap.org/soap/encoding/"">
    <a>hello</a>
  </env:Body>
</env:Envelope>";

            this.xmlTester.ArrangeExpectedXml(expectedXml);
        }
Esempio n. 29
0
        public void WhenTheBodyIsSpecifiedTwice()
        {
            this.soapEnvelope = SoapBuilder.CreateSoap11Envelope()
                                .WithBody.AddEntry("<a>body entry 1</a>")
                                .WithBody.AddEntry("<b>body entry 2</b>")
                                .Build()
                                .ToString();

            this.xmlTester.ArrangeActualXml(this.soapEnvelope);

            var expectedXml =
                @"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/"">
  <env:Body>
    <a>body entry 1</a>
    <b>body entry 2</b>
  </env:Body>
</env:Envelope>";

            this.xmlTester.ArrangeExpectedXml(expectedXml);
        }
        public void WhenTheBodyIsSpecifiedTwice()
        {
            this.soapEnvelope = SoapBuilder.CreateSoap12Envelope()
                                .WithBody.AddEntry("<a>body entry 1</a>")
                                .WithBody.AddEntry("<b>body entry 2</b>")
                                .Build()
                                .ToString();

            this.xmlTester.ArrangeActualXml(this.soapEnvelope);

            const string expectedXml =
                @"<env:Envelope xmlns:env=""http://www.w3.org/2003/05/soap-envelope"">
  <env:Body>
    <a>body entry 1</a>
    <b>body entry 2</b>
  </env:Body>
</env:Envelope>";

            this.xmlTester.ArrangeExpectedXml(expectedXml);
        }