public EnvelopeSettings(SoapVersion version)
        {
            SoapVersion = version;

            BodyId = string.Format("id-{0}", Guid.NewGuid());
            TimestampId = String.Format("TS-{0}", Guid.NewGuid());
        }
        /// <summary>
        /// A method used to initialize the helper. It will get necessary values from configuration properties.
        /// </summary>
        /// <param name="testSiteInstance">A parameter represents the ITestSite instance.</param>
        public static void Initialize(ITestSite testSiteInstance)
        {
            if (null == testSiteInstance)
            {
                throw new ArgumentNullException("testSiteInstance");
            }

            lock (threadLockObjectOfInitiazeStatus)
            {
                if (hasInitialized)
                {
                    return;
                }

                testSiteInstance.DefaultProtocolDocShortName = "MS-COPYS";

                // Merge Common configuration file.
                string commonConfigFileName = Common.GetConfigurationPropertyValue("CommonConfigurationFileName", testSiteInstance);
                Common.MergeGlobalConfig(commonConfigFileName, testSiteInstance);

                // Getting required configuration properties.
                currentSoapVersion        = Common.GetConfigurationPropertyValue <SoapVersion>("SoapVersion", testSiteInstance);
                currentTransportType      = Common.GetConfigurationPropertyValue <TransportProtocol>("TransportType", testSiteInstance);
                defaultUser               = Common.GetConfigurationPropertyValue("UserName", testSiteInstance);
                domainOfDefaultUser       = Common.GetConfigurationPropertyValue("Domain", testSiteInstance);
                passwordOfDefaultUser     = Common.GetConfigurationPropertyValue("Password", testSiteInstance);
                targetServiceUrlOfMSCOPYS = Common.GetConfigurationPropertyValue("TargetServiceUrlOfDestinationSUT", testSiteInstance);
                int soapTimeOutValueInMintues = Common.GetConfigurationPropertyValue <int>("ServiceTimeOut", testSiteInstance);
                soapTimeOutValue = soapTimeOutValueInMintues * 60000;

                // Setting the initialization status.
                hasInitialized = true;
            }
        }
        /// <summary>
        /// This method is used to verify the requirements about the transport.
        /// </summary>
        private void CaptureTransportRelatedRequirements()
        {
            TransportProtocol transport = Common.GetConfigurationPropertyValue <TransportProtocol>("TransportType", this.Site);

            switch (transport)
            {
            case TransportProtocol.HTTP:

                // As response successfully returned, the transport related requirements can be directly captured.
                Site.CaptureRequirement(
                    1,
                    @"[In Transport] Protocol servers MUST support SOAP over HTTP.");
                break;

            case TransportProtocol.HTTPS:
                if (Common.IsRequirementEnabled(121, this.Site))
                {
                    // Having received the response successfully have proved the HTTPS
                    // transport is supported. If the HTTPS transport is not supported, the
                    // response can't be received successfully.
                    Site.CaptureRequirement(
                        121,
                        @"[In Appendix B: Product Behavior] Implementation does additionally support SOAP over HTTPS to help secure communication with protocol clients.(The Windows SharePoint Services 3.0 and above products follow this behavior.)");
                }

                break;

            default:

                Site.Debug.Fail("Unknown transport type " + transport);
                break;
            }

            SoapVersion soapVersion = Common.GetConfigurationPropertyValue <SoapVersion>("SoapVersion", this.Site);

            switch (soapVersion)
            {
            case SoapVersion.SOAP11:

                // As response successfully returned, the SOAP1.1 related requirements can be directly captured.
                Site.CaptureRequirement(
                    122,
                    @"[In Transport] Protocol messages MUST be formatted as specified in [SOAP1.1] section 4 [or [SOAP1.2/1] section 5].");

                break;

            case SoapVersion.SOAP12:

                // As response successfully returned, the SOAP1.2 related requirements can be directly captured.
                Site.CaptureRequirement(
                    123,
                    @"[In Transport] Protocol messages MUST be formatted as specified in [SOAP1.2/1] section 5.");

                break;

            default:
                Site.Debug.Fail("Unknown soap version" + soapVersion);
                break;
            }
        }
Beispiel #4
0
        public void PostAsync_ShouldCancelExpectedHttpCall(
            Uri endpoint,
            string action,
            SoapVersion soapVersion,
            List <XElement> bodies,
            List <XElement> headers)
        {
            // Setup
            // -- We use TestMessageHandler in order to check what call does the inner HttpClient made
            var tokenSource        = new CancellationTokenSource();
            var token              = tokenSource.Token;
            var testMessageHandler = new TestMessageHandler();
            var httpClient         = new HttpClient(testMessageHandler);
            var sut = new SoapClient(() => httpClient);

            // Exercise
            var task = sut.PostAsync(endpoint, soapVersion, bodies, headers, action, token);

            // Verify outcome
            // -- Assert that cancellation has been requested.
            tokenSource.Cancel(true);
            Task.WaitAll(task);
            Assert.True(token.IsCancellationRequested);
            Console.WriteLine(task.Result);
        }
Beispiel #5
0
        public void MSWEBSS_S10_TC05_GetActivatedFeatures_failure()
        {
            SoapVersion soapVersion     = Common.GetConfigurationPropertyValue <SoapVersion>("SoapVersion", this.Site);
            string      transport       = Common.GetConfigurationPropertyValue("TransportType", this.Site);
            string      sutComputerName = Common.GetConfigurationPropertyValue("SutComputerName", this.Site);
            string      url             = string.Format("{0}://{1}/Invalid/_vti_bin/Webs.asmx ", transport, sutComputerName);

            switch (soapVersion)
            {
            case SoapVersion.SOAP11:
            {
                Adapter.InitializeService(AdapterHelper.GetTransportType(), SoapProtocolVersion.Soap11, UserAuthentication.Authenticated, url);
                break;
            }

            default:
            {
                Adapter.InitializeService(AdapterHelper.GetTransportType(), SoapProtocolVersion.Soap12, UserAuthentication.Authenticated, url);
                break;
            }
            }
            try
            {
                Adapter.GetActivatedFeatures();
            }
            catch (SoapException)
            {
                // Catch the exception, then the following requirements will be captured.
                // Verify MS-WEBSS requirement: MS-WEBSS_R139
                Site.CaptureRequirement(
                    139,
                    @"[In GetActivatedFeaturesResponse] If the protocol client sends the GetActivatedFeaturesSoapIn request message to a protocol server URL that does not correspond to a site, the protocol server MUST return a SOAP fault.");
            }
        }
        /// <summary>
        /// Initialize SUT control adapter.
        /// </summary>
        /// <param name="testSite">The test site instance associated with the current adapter.</param>
        public override void Initialize(ITestSite testSite)
        {
            base.Initialize(testSite);
            AdapterHelper.Initialize(testSite);

            this.listsService = new ListsSoap();

            string transportType = Common.GetConfigurationPropertyValue("TransportType", testSite);

            this.listsService.Url = Common.GetConfigurationPropertyValue("MSLISTSWSServiceUrl", testSite);

            string domain       = Common.GetConfigurationPropertyValue("Domain", testSite);
            string userName     = Common.GetConfigurationPropertyValue("UserName", testSite);
            string userPassword = Common.GetConfigurationPropertyValue("Password", testSite);

            this.listsService.Credentials = new NetworkCredential(userName, userPassword, domain);

            SoapVersion soapVersion = Common.GetConfigurationPropertyValue <SoapVersion>("SoapVersion", this.Site);

            switch (soapVersion)
            {
            case SoapVersion.SOAP11:
                this.listsService.SoapVersion = SoapProtocolVersion.Soap11;
                break;

            default:
                this.listsService.SoapVersion = SoapProtocolVersion.Soap12;
                break;
            }

            if (string.Compare(transportType, "https", true, System.Globalization.CultureInfo.CurrentCulture) == 0)
            {
                Common.AcceptServerCertificate();
            }
        }
Beispiel #7
0
        /// <summary>
        ///     Get the Soap12 Action from the xml content
        /// </summary>
        /// <param name="request"></param>
        /// <param name="requestContent"></param>
        /// <returns></returns>
        private string GetSoapAction(HttpListenerRequest request, string requestContent)
        {
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(requestContent);
                SoapVersion soapVer = GetMessageSoapVersion(xmlDoc);
                _testContext.WriteLine("MOXY: Got soap version: {0}", soapVer);
                switch (soapVer)
                {
                case SoapVersion.Soap11:
                    return(request.Headers["SOAPAction"]);

                case SoapVersion.Soap12:
                    XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
                    nsmgr.AddNamespace("s", Soap12Namespace);
                    nsmgr.AddNamespace("a", Soap12AddressingNamespace);
                    var actionNode = xmlDoc.SelectSingleNode(Soap12ActionNodeXpath, nsmgr);
                    if (actionNode != null && !string.IsNullOrWhiteSpace(actionNode.InnerText))
                    {
                        return(actionNode.InnerText);
                    }
                    break;
                }
            }
            catch (XmlException)
            {
                // kinda wonky if the XML doesn't parse, ignore: for this context Soap action is set null
            }
            catch (XPathException)
            {
                // failed xpath, due to namespace not defined, ignore: for this context Soap action is set null
            }
            return(null);
        }
Beispiel #8
0
        public async void PostAsync_ShouldDoExpectedHttpCall(
            Uri endpoint,
            string action,
            SoapVersion soapVersion,
            List <XElement> bodies,
            List <XElement> headers)
        {
            // Setup
            // -- We use TestMessageHandler in order to check what call does the inner HttpClient made
            var testMessageHandler = new TestMessageHandler();
            var httpClient         = new HttpClient(testMessageHandler);
            var sut = new SoapClient(() => httpClient);

            // Exercise
            var actual = await sut.PostAsync(endpoint, soapVersion, bodies, headers, action);

            // Verify outcome
            // -- Assert that we only made one call
            actual.StatusCode.Should().Be(HttpStatusCode.OK);
            var actualCall = testMessageHandler.CallStack.Should().ContainSingle().Subject;

            // -- Assert the endpoint
            actualCall.Uri.Should().Be(endpoint);
            // -- Assert the headers
            AssertActualHeaders(actualCall.Headers, soapVersion, action);
            // -- Assert the request body
            AssertRequestBody(soapVersion, actualCall.Body, bodies, headers);
        }
Beispiel #9
0
        public EnvelopeSettings(SoapVersion version)
        {
            SoapVersion = version;

            BodyId      = string.Format("id-{0}", Guid.NewGuid());
            TimestampId = String.Format("TS-{0}", Guid.NewGuid());
        }
 /// <summary>
 /// Posts an asynchronous message.
 /// </summary>
 /// <param name="client">Instance of SoapClient.</param>
 /// <param name="endpoint">The endpoint.</param>
 /// <param name="soapVersion">The version of SOAP</param>
 /// <param name="body">The body of the SOAP message.</param>
 /// <param name="headers">The headers of the SOAP message.</param>
 /// <param name="action"></param>
 public static HttpResponseMessage Post(
     this ISoapClient client,
     Uri endpoint,
     SoapVersion soapVersion,
     XElement body,
     IEnumerable <XElement> headers,
     string?action = null)
 => ResolveTask(() =>
                client.PostAsync(endpoint, soapVersion, body, headers, action));
Beispiel #11
0
        /// <inheritdoc />
        public Task <HttpResponseMessage> PostAsync(
            Uri endpoint,
            SoapVersion soapVersion,
            IEnumerable <XElement> bodies,
            IEnumerable <XElement> headers = null,
            string action = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (endpoint == null)
            {
                throw new ArgumentNullException(nameof(endpoint));
            }

            if (bodies == null)
            {
                throw new ArgumentNullException(nameof(bodies));
            }

            if (!bodies.Any())
            {
                throw new ArgumentException("Bodies element cannot be empty", nameof(bodies));
            }

            // Get configuration based on version
            var messageConfiguration = new SoapMessageConfiguration(soapVersion);

            // Get the envelope
            var envelope = GetEnvelope(messageConfiguration);

            // Add headers
            if (headers != null && headers.Any())
            {
                envelope.Add(new XElement(messageConfiguration.Schema + "Header", headers));
            }

            // Add bodies
            envelope.Add(new XElement(messageConfiguration.Schema + "Body", bodies));

            // Get HTTP content
            var content = new StringContent(envelope.ToString(), Encoding.UTF8, messageConfiguration.MediaType);

            // Add SOAP action if any
            if (action != null)
            {
                content.Headers.Add("SOAPAction", action);

                if (messageConfiguration.SoapVersion == SoapVersion.Soap12)
                {
                    content.Headers.ContentType.Parameters.Add(
                        new NameValueHeaderValue("ActionParameter", $"\"{action}\""));
                }
            }

            // Execute call
            return(_httpClient.PostAsync(endpoint, content, cancellationToken));
        }
Beispiel #12
0
        private static void AssertRequestBody(
            SoapVersion soapVersion,
            string body,
            IEnumerable <XElement> bodies,
            IReadOnlyCollection <XElement> headers)
        {
            // Get Namespaces
            var expectedNameSpace =
                (soapVersion == SoapVersion.Soap11)
                    ? "http://schemas.xmlsoap.org/soap/envelope/"
                    : "http://www.w3.org/2003/05/soap-envelope";

            var actualEnvelope = XElement.Parse(body);

            // Assert Envelope
            actualEnvelope.Name.LocalName.Should().Be("Envelope");
            actualEnvelope.Name.Namespace.NamespaceName.Should().Be(expectedNameSpace);

            // Assert Headers

            if (headers != null && headers.Any())
            {
                var actualHeader =
                    actualEnvelope.Elements()
                    .Where(e => e.Name.LocalName == "Header")
                    .Where(e => e.Name.Namespace.NamespaceName == expectedNameSpace)
                    .Should()
                    .ContainSingle()
                    .Subject;

                // Since FluentAssertions Should().Be(...) compares by instance and we dont have the same instance
                // And Should().BeEquivalentTo(...) compares by object graph and generates a memory degration
                // we will compare the elements using the .ToString() serialization of the XML
                actualHeader.Elements().Select(e => e.ToString())
                .Should().BeEquivalentTo(headers.Select(e => e.ToString()));
            }

            // Assert Bodies
            var actualBody =
                actualEnvelope.Elements()
                .Where(e => e.Name.LocalName == "Body")
                .Where(e => e.Name.Namespace.NamespaceName == expectedNameSpace)
                .Should()
                .ContainSingle()
                .Subject;

            // Since FluentAssertions Should().Be(...) compares by instance and we dont have the same instance
            // And Should().BeEquivalentTo(...) compares by object graph and generates a memory degration
            // we will compare the elements using the .ToString() serialization of the XML
            actualBody.Elements().Select(e => e.ToString())
            .Should().BeEquivalentTo(bodies.Select(e => e.ToString()));
        }
 /// <summary>
 /// Creates a new <see cref="DynamicWebServiceProxy"/> instance.
 /// </summary>
 /// <param name="wsdlLocation">Location of WSDL file</param>
 /// <param name="enableMessageAccess">Enables access to SOAP messages</param>
 /// <param name="wsdlCache">Type of caching to be used</param>
 /// <param name="certificate">Certificate to use.</param>
 /// <param name="version"></param>
 internal DynamicWebServiceProxy(string wsdlLocation, bool enableMessageAccess = false, WsdlCache wsdlCache = WsdlCache.Both, X509Certificate2 certificate = null, SoapVersion? version = null)
 {
     this.wsdl = wsdlLocation;
     this.enableMessageAccess = enableMessageAccess;
     this.serviceCache = new ServiceCache(wsdlLocation, wsdlCache, new ServiceCache.CacheMissEvent(BuildAssemblyFromWsdl));
     this.certificate = certificate;
     this.version = version;
     if (this.version == SoapVersion.SOAP_1_2)
         protocolName = "Soap12";
     else if (this.version == SoapVersion.SOAP_1_1)
         protocolName = "Soap";
     BuildProxy();
 }
Beispiel #14
0
 private static void AssertActualHeaders(HttpContentHeaders headers, SoapVersion soapVersion, string action)
 {
     if (headers.Contains("ActionHeader"))
     {
         soapVersion.Should().Be(SoapVersion.Soap11);
         headers.GetValues("ActionHeader").Single().Should().Be(action);
     }
     else if (headers.ContentType.Parameters.Any(e => e.Name == "ActionParameter"))
     {
         var actionParam = headers.ContentType.Parameters.Single(e => e.Name == "ActionParameter");
         actionParam.Value.Should().Be($"\"{action}\"");
         soapVersion.Should().Be(SoapVersion.Soap12);
     }
 }
        /// <summary>
        /// Initialize the protocol adapter.
        /// </summary>
        /// <param name="testSite">Transfer ITestSite into adapter, make adapter can use ITestSite's function.</param>
        public override void Initialize(ITestSite testSite)
        {
            base.Initialize(testSite);
            testSite.DefaultProtocolDocShortName = "MS-VERSS";
            AdapterHelper.Initialize(testSite);

            if (this.service == null)
            {
                string globalConfigFileName = Common.GetConfigurationPropertyValue("CommonConfigurationFileName", testSite);
                Common.MergeGlobalConfig(globalConfigFileName, testSite);
                Common.CheckCommonProperties(this.Site, true);
                Common.MergeSHOULDMAYConfig(testSite);

                this.service = Proxy.CreateProxy <VersionsSoap>(testSite);

                this.service.Url = Common.GetConfigurationPropertyValue("MSVERSSServiceUrl", testSite);

                SoapVersion soapVersion = Common.GetConfigurationPropertyValue <SoapVersion>("SoapVersion", this.Site);
                switch (soapVersion)
                {
                case SoapVersion.SOAP11:
                    this.service.SoapVersion = SoapProtocolVersion.Soap11;
                    break;

                default:
                    this.service.SoapVersion = SoapProtocolVersion.Soap12;
                    break;
                }

                TransportProtocol transportType = Common.GetConfigurationPropertyValue <TransportProtocol>("TransportType", this.Site);
                switch (transportType)
                {
                case TransportProtocol.HTTPS:
                    Common.AcceptServerCertificate();
                    this.transportProtocol = TransportProtocol.HTTPS;
                    break;

                default:
                    this.transportProtocol = TransportProtocol.HTTP;
                    break;
                }
            }

            string domain       = Common.GetConfigurationPropertyValue("Domain", testSite);
            string userName     = Common.GetConfigurationPropertyValue("UserName", testSite);
            string userPassword = Common.GetConfigurationPropertyValue("Password", testSite);

            this.service.Credentials = new NetworkCredential(userName, userPassword, domain);
        }
Beispiel #16
0
 public WebServiceCall(string endpointURL, string WSDLTargetNamespace, string operationName, string soapAction, string encoding, CallStyle style, SoapVersion soapVersion)
 {
     this.endpointURL         = endpointURL;
     this.soapAction          = soapAction;
     this.encoding            = encoding;
     this.WSDLTargetNamespace = WSDLTargetNamespace;
     this.operationName       = operationName;
     this.style       = style;
     this.soapVersion = soapVersion;
     if (soapVersion == SoapVersion.SOAP12)
     {
         soapEnvNs = "http://www.w3.org/2003/05/soap-envelope";
         soapEncNs = "http:// www.w3.org/2003/05/soap-encoding";
     }
 }
        public SoapMessageConfiguration(SoapVersion soapVersion)
        {
            if (soapVersion == SoapVersion.Soap11)
            {
                MediaType = "text/xml";
                Schema    = "http://schemas.xmlsoap.org/soap/envelope/";
            }
            else
            {
                MediaType = "application/soap+xml";
                Schema    = "http://www.w3.org/2003/05/soap-envelope";
            }

            SoapVersion = soapVersion;
        }
 /// <summary>
 /// Posts an asynchronous message.
 /// </summary>
 /// <param name="client">Instance of SoapClient.</param>
 /// <param name="endpoint">The endpoint.</param>
 /// <param name="soapVersion">The version of SOAP</param>
 /// <param name="bodies">The bodies of the SOAP message.</param>
 /// <param name="header">The header of the SOAP message.</param>
 /// <param name="action"></param>
 public static Task <HttpResponseMessage> PostAsync(
     this ISoapClient client,
     Uri endpoint,
     SoapVersion soapVersion,
     IEnumerable <XElement> bodies,
     XElement header,
     string action = null)
 {
     return(client.PostAsync(
                endpoint,
                soapVersion,
                bodies,
                header != null ? new[] { header } : default(IEnumerable <XElement>),
                action));
 }
 /// <summary>
 /// Posts an asynchronous message.
 /// </summary>
 /// <param name="client">Instance of SoapClient.</param>
 /// <param name="endpoint">The endpoint.</param>
 /// <param name="soapVersion">The version of SOAP</param>
 /// <param name="body">The body of the SOAP message.</param>
 /// <param name="headers">The headers of the SOAP message.</param>
 /// <param name="action"></param>
 public static Task <HttpResponseMessage> PostAsync(
     this ISoapClient client,
     Uri endpoint,
     SoapVersion soapVersion,
     XElement body,
     IEnumerable <XElement> headers,
     string action = null)
 {
     return(client.PostAsync(
                endpoint,
                soapVersion,
                new[] { body },
                headers,
                action));
 }
 /// <summary>
 /// Posts an asynchronous message.
 /// </summary>
 /// <param name="client">Instance of SoapClient.</param>
 /// <param name="endpoint">The endpoint.</param>
 /// <param name="soapVersion">The version of SOAP</param>
 /// <param name="body">The body of the SOAP message.</param>
 /// <param name="header">The header of the SOAP message.</param>
 /// <param name="action"></param>
 public static Task <HttpResponseMessage> PostAsync(
     this ISoapClient client,
     Uri endpoint,
     SoapVersion soapVersion,
     XElement body,
     XElement?header = null,
     string?action   = null,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(client.PostAsync(
                endpoint,
                soapVersion,
                new[] { body },
                header != null ? new[] { header } : default(IEnumerable <XElement>),
                action,
                cancellationToken));
 }
 /// <summary>
 /// Posts an asynchronous message.
 /// </summary>
 /// <param name="client">Instance of SoapClient.</param>
 /// <param name="endpoint">The endpoint.</param>
 /// <param name="soapVersion">The version of SOAP</param>
 /// <param name="bodies">The bodies of the SOAP message.</param>
 /// <param name="header">The header of the SOAP message.</param>
 /// <param name="action"></param>
 public static Task <HttpResponseMessage> PostAsync(
     this ISoapClient client,
     Uri endpoint,
     SoapVersion soapVersion,
     IEnumerable <XElement> bodies,
     XElement header,
     string?action = null,
     CancellationToken cancellationToken = default(CancellationToken))
 {
     return(client.PostAsync(
                endpoint,
                soapVersion,
                bodies,
                new[] { header },
                action,
                cancellationToken));
 }
        /// <summary>
        /// This operation is used to initialize sites service with authority information.
        /// </summary>
        /// <param name="userAuthentication">This parameter used to assign the authentication information of web service.</param>
        public void InitializeWebService(UserAuthenticationOption userAuthentication)
        {
            this.service = Proxy.CreateProxy <SitesSoap>(this.Site);

            // Configure the soap service timeout.
            string soapServiceTimeOut = Common.GetConfigurationPropertyValue(Constants.SoapServiceTimeOut, this.Site);

            this.service.Timeout = Convert.ToInt32(soapServiceTimeOut) * 1000;

            TransportProtocol transport = Common.GetConfigurationPropertyValue <TransportProtocol>("TransportType", this.Site);

            switch (transport)
            {
            case TransportProtocol.HTTP:
                this.transportProtocol = TransportType.HTTP;
                break;

            default:
                this.transportProtocol = TransportType.HTTPS;
                break;
            }

            SoapVersion soapVersion = Common.GetConfigurationPropertyValue <SoapVersion>("SoapVersion", this.Site);

            switch (soapVersion)
            {
            case SoapVersion.SOAP11:
                this.service.SoapVersion = SoapProtocolVersion.Soap11;
                break;

            default:
                this.service.SoapVersion = SoapProtocolVersion.Soap12;
                break;
            }

            this.service.Url = Common.GetConfigurationPropertyValue(Constants.ServiceUrl, this.Site);

            if (this.transportProtocol == TransportType.HTTPS)
            {
                Common.AcceptServerCertificate();
            }

            this.SetLoginUser(userAuthentication);
        }
Beispiel #23
0
        /// <summary>
        /// Initialize the services of WEBSS with the specified transport type, soap version and user authentication provided by the test case.
        /// </summary>
        /// <param name="userAuthentication">a user authenticated</param>
        public void InitializeService(UserAuthentication userAuthentication)
        {
            SoapVersion soapVersion = Common.GetConfigurationPropertyValue <SoapVersion>("SoapVersion", this.Site);

            switch (soapVersion)
            {
            case SoapVersion.SOAP11:
            {
                this.InitializeService(AdapterHelper.GetTransportType(), SoapProtocolVersion.Soap11, userAuthentication, Common.GetConfigurationPropertyValue("TargetServiceUrl", this.Site));
                break;
            }

            default:
            {
                this.InitializeService(AdapterHelper.GetTransportType(), SoapProtocolVersion.Soap12, userAuthentication, Common.GetConfigurationPropertyValue("TargetServiceUrl", this.Site));
                break;
            }
            }
        }
Beispiel #24
0
        /// <summary>
        /// Set the SOAP version according to the SoapVersion property.
        /// </summary>
        /// <param name="adminProxy">set admin proxy</param>
        private void SetSoapVersion(AdminSoap adminProxy)
        {
            SoapVersion soapVersion = Common.GetConfigurationPropertyValue <SoapVersion>("SoapVersion", this.Site);

            switch (soapVersion)
            {
            case SoapVersion.SOAP11:
            {
                adminProxy.SoapVersion = SoapProtocolVersion.Soap11;
                break;
            }

            default:
            {
                adminProxy.SoapVersion = SoapProtocolVersion.Soap12;
                break;
            }
            }
        }
Beispiel #25
0
    /// <summary>
    /// Posts an asynchronous message.
    /// </summary>
    /// <param name="client">Instance of SoapClient.</param>
    /// <param name="endpoint">The endpoint.</param>
    /// <param name="soapVersion">The version of SOAP</param>
    /// <param name="body">The body of the SOAP message.</param>
    /// <param name="header">The header of the SOAP message.</param>
    /// <param name="action"></param>
    public static HttpResponseMessage Post(
        this ISoapClient client,
        Uri endpoint,
        SoapVersion soapVersion,
        object body,
        object?header = null,
        IXElementSerializer?xElementSerializer = null,
        string?action = null)
    {
        if (xElementSerializer == null)
        {
            xElementSerializer = new XElementSerializer();
        }

        return(client.Post(endpoint,
                           soapVersion,
                           xElementSerializer.Serialize(body),
                           header != null ? new[] { xElementSerializer.Serialize(header) } : Enumerable.Empty <XElement>()));
    }
Beispiel #26
0
        /// <summary>
        /// Posts an asynchronous message.
        /// </summary>
        /// <param name="client">Instance of SoapClient.</param>
        /// <param name="endpoint">The endpoint.</param>
        /// <param name="soapVersion">The version of SOAP</param>
        /// <param name="body">The body of the SOAP message.</param>
        /// <param name="header">The header of the SOAP message.</param>
        /// <param name="action"></param>
        public static Task <HttpResponseMessage> PostAsync(
            this ISoapClient client,
            Uri endpoint,
            SoapVersion soapVersion,
            object body,
            object header = null,
            IXElementSerializer xElementSerializer = null,
            string action = null)
        {
            if (xElementSerializer == null)
            {
                xElementSerializer = new XElementSerializer();
            }

            return(client.PostAsync(endpoint,
                                    soapVersion,
                                    xElementSerializer.Serialize(body),
                                    header != null ? new[] { xElementSerializer.Serialize(header) } : default(IEnumerable <XElement>),
                                    action));
        }
        /// <summary>
        /// Set the SOAP version according to the SoapVersion property.
        /// </summary>
        /// <param name="dwsSoap">set meeting proxy</param>
        private void SetSoapVersion(DwsSoap dwsSoap)
        {
            this.soapVersion = Common.GetConfigurationPropertyValue <SoapVersion>("SoapVersion", this.Site);

            if (this.soapVersion == SoapVersion.SOAP11)
            {
                dwsSoap.SoapVersion = SoapProtocolVersion.Soap11;
            }
            else if (this.soapVersion == SoapVersion.SOAP12)
            {
                dwsSoap.SoapVersion = SoapProtocolVersion.Soap12;
            }
            else
            {
                Site.Assume.Fail(
                    "Property SoapVersion value must be {0} or {1} at the ptfconfig file.",
                    SoapVersion.SOAP11.ToString(),
                    SoapVersion.SOAP12.ToString());
            }
        }
Beispiel #28
0
    /// <summary>
    /// Posts an asynchronous message.
    /// </summary>
    /// <param name="client">Instance of SoapClient.</param>
    /// <param name="endpoint">The endpoint.</param>
    /// <param name="soapVersion">The version of SOAP</param>
    /// <param name="body">The body of the SOAP message.</param>
    /// <param name="headers">The headers of the SOAP message.</param>
    /// <param name="action"></param>
    public static HttpResponseMessage Post(
        this ISoapClient client,
        Uri endpoint,
        SoapVersion soapVersion,
        object body,
        IEnumerable <object> headers,
        IXElementSerializer?xElementSerializer = null,
        string?action = null)
    {
        if (xElementSerializer == null)
        {
            xElementSerializer = new XElementSerializer();
        }

        return(client.Post(endpoint,
                           soapVersion,
                           xElementSerializer.Serialize(body),
                           headers.Select(e => xElementSerializer.Serialize(e)),
                           action));
    }
        /// <summary>
        /// Posts an asynchronous message.
        /// </summary>
        /// <param name="client">Instance of SoapClient.</param>
        /// <param name="endpoint">The endpoint.</param>
        /// <param name="soapVersion">The version of SOAP</param>
        /// <param name="bodies">The body of the SOAP message.</param>
        /// <param name="header">The header of the SOAP message.</param>
        /// <param name="action"></param>
        public static HttpResponseMessage Post(
            this ISoapClient client,
            Uri endpoint,
            SoapVersion soapVersion,
            IEnumerable <object> bodies,
            object header,
            IXElementSerializer xElementSerializer = null,
            string action = null)
        {
            if (xElementSerializer == null)
            {
                xElementSerializer = new XElementSerializer();
            }

            return(client.Post(endpoint,
                               soapVersion,
                               bodies.Select(e => xElementSerializer.Serialize(e)),
                               header != null ? xElementSerializer.Serialize(header) : default(XElement),
                               action));
        }
        public ResponseValidator(System.IO.Stream stream, SoapVersion version, XmlDocument sentEnvelope, X509Certificate2 xmlDekrypteringsSertifikat = null)
        {
            SentEnvelope = sentEnvelope;

            ResponseDocument = new XmlDocument();
            ResponseDocument.Load(stream);

            Nsmgr = new XmlNamespaceManager(ResponseDocument.NameTable);
            Nsmgr.AddNamespace("env", version == SoapVersion.Soap11 ? Navnerom.SoapEnvelope : Navnerom.SoapEnvelopeEnv12);
            Nsmgr.AddNamespace("wsse", Navnerom.WssecuritySecext10);
            Nsmgr.AddNamespace("ds", Navnerom.XmlDsig);
            Nsmgr.AddNamespace("xenc", Navnerom.xenc);
            Nsmgr.AddNamespace("wsse11", Navnerom.WssecuritySecext11);
            Nsmgr.AddNamespace("wsu", Navnerom.WssecurityUtility10);

            HeaderSecurityElement = ResponseDocument.SelectSingleNode("/env:Envelope/env:Header/wsse:Security", Nsmgr) as XmlElement;
            HeaderSignatureElement = HeaderSecurityElement.SelectSingleNode("./ds:Signature", Nsmgr) as XmlElement;

            if (xmlDekrypteringsSertifikat != null)
                DecryptDocument(xmlDekrypteringsSertifikat);
        }
    /// <summary>
    /// Posts an asynchronous message.
    /// </summary>
    /// <param name="client">Instance of SoapClient.</param>
    /// <param name="endpoint">The endpoint.</param>
    /// <param name="soapVersion">The version of SOAP</param>
    /// <param name="bodies">The bodies of the SOAP message.</param>
    /// <param name="header">The header of the SOAP message.</param>
    /// <param name="action"></param>
    public static Task <HttpResponseMessage> PostAsync(
        this ISoapClient client,
        Uri endpoint,
        SoapVersion soapVersion,
        IEnumerable <object> bodies,
        object header,
        IXElementSerializer?xElementSerializer = null,
        string?action = null,
        CancellationToken cancellationToken = default(CancellationToken))
    {
        if (xElementSerializer == null)
        {
            xElementSerializer = new XElementSerializer();
        }

        return(client.PostAsync(endpoint,
                                soapVersion,
                                bodies.Select(e => xElementSerializer.Serialize(e)),
                                header != null ? new[] { xElementSerializer.Serialize(header) } : Enumerable.Empty <XElement>(),
                                action,
                                cancellationToken));
    }
Beispiel #32
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="SoapClient" /> class.
        /// </summary>
        /// <param name="httpClientFactory">Allows the user to define the construction of the HttpClient</param>
        /// <param name="version">Optionally provide a preferred SOAP version. Defaults to SOAP 1.1.</param>
        public SoapClient(Func <HttpClient> httpClientFactory, SoapVersion version = SoapVersion.Soap11)
        {
            _version = version;
            switch (version)
            {
            case SoapVersion.Soap11:
                _soapSchema = "http://schemas.xmlsoap.org/soap/envelope/";
                _mediaType  = "text/xml";
                break;

            case SoapVersion.Soap12:
                _soapSchema = "http://www.w3.org/2003/05/soap-envelope";
                _mediaType  = "application/soap+xml";
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(version), version,
                                                      $"The {version.GetType().Name} enum contains an unsupported value.");
            }

            _httpClient = httpClientFactory();
        }
Beispiel #33
0
        /// <summary>
        /// Posts an asynchronous message.
        /// </summary>
        /// <param name="client">Instance of SoapClient.</param>
        /// <param name="endpoint">The endpoint.</param>
        /// <param name="soapVersion">The version of SOAP</param>
        /// <param name="body">The body of the SOAP message.</param>
        /// <param name="headers">The headers of the SOAP message.</param>
        /// <param name="action"></param>
        public static Task <HttpResponseMessage> PostAsync(
            this ISoapClient client,
            Uri endpoint,
            SoapVersion soapVersion,
            object body,
            IEnumerable <object> headers,
            IXElementSerializer xElementSerializer = null,
            string action = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            if (xElementSerializer == null)
            {
                xElementSerializer = new XElementSerializer();
            }

            return(client.PostAsync(endpoint,
                                    soapVersion,
                                    xElementSerializer.Serialize(body),
                                    headers.Select(e => xElementSerializer.Serialize(e)),
                                    action,
                                    cancellationToken));
        }
        /// <summary>
        /// A method used to initialize the helper. It will get necessary values from configuration properties.
        /// </summary>
        /// <param name="testSiteInstance">A parameter represents the ITestSite instance.</param>
        public static void Initialize(ITestSite testSiteInstance)
        {
            if (null == testSiteInstance)
            {
                throw new ArgumentNullException("testSiteInstance");
            }

            lock (threadLockObjectOfInitiazeStatus)
            {
                if (hasInitialized)
                {
                    return;
                }

                testSiteInstance.DefaultProtocolDocShortName = "MS-COPYS";

                // Merge Common configuration file.
                string commonConfigFileName = Common.GetConfigurationPropertyValue("CommonConfigurationFileName", testSiteInstance);
                Common.MergeGlobalConfig(commonConfigFileName, testSiteInstance);

                // Getting required configuration properties.
                currentSoapVersion = Common.GetConfigurationPropertyValue<SoapVersion>("SoapVersion", testSiteInstance);
                currentTransportType = Common.GetConfigurationPropertyValue<TransportProtocol>("TransportType", testSiteInstance);
                defaultUser = Common.GetConfigurationPropertyValue("UserName", testSiteInstance);
                domainOfDefaultUser = Common.GetConfigurationPropertyValue("Domain", testSiteInstance);
                passwordOfDefaultUser = Common.GetConfigurationPropertyValue("Password", testSiteInstance);
                targetServiceUrlOfMSCOPYS = Common.GetConfigurationPropertyValue("TargetServiceUrlOfDestinationSUT", testSiteInstance);
                int soapTimeOutValueInMintues = Common.GetConfigurationPropertyValue<int>("ServiceTimeOut", testSiteInstance);
                soapTimeOutValue = soapTimeOutValueInMintues * 60000;
 
                // Setting the initialization status.
                hasInitialized = true;
            }
        }
Beispiel #35
0
        private void HandleHeaders(ServiceDescription wsdl, BindingOperationType op2, ItemsChoiceType1 type, MessageBinding mb, SoapVersion v)
        {
            if (op2.Items == null)
                return;

            for (int i = 0; i < op2.Items.Length; i++)
            {
                var curr = op2.Items[i] as BindingOperationMessageType;
                if (curr == null)
                    continue;

                if (op2.ItemsElementName[i] != type)
                    continue;

                if (curr.Items == null)
                    continue;

                var headers = curr.Items.Where(s => s.LocalName == "header"
                    && s.NamespaceURI == "http://www.w3.org/ns/wsdl/soap");
                foreach (var n in headers)
                {
                    var header = v == SoapVersion.Soap11 ? new SoapHeaderBinding() : new Soap12HeaderBinding();
                    header.Use = SoapBindingUse.Literal;

                    if (n.Attributes["element"] == null)
                        return;

                    var qName = new XmlQualifiedName(n.Attributes["element"].Value);
                    const string partName = "H";
                    header.Message = CreateMessage(wsdl, String.Format("{0}Header_{1}", [email protected], unique++), qName, partName);
                    header.Part = partName;

                    mb.Extensions.Add(header);
                }

            }
        }
Beispiel #36
0
        public void __construct(string wsdl, [Optional] PhpArray options)
        {
            bool enableMessageAccess = false;
            WsdlCache wsdlCache = WsdlCache.Both;
            X509Certificate2 certificate = null;

            if (options != null)
            {
                object value;
                
                if (options.TryGetValue("trace", out value))
                {
                    enableMessageAccess = PHP.Core.Convert.ObjectToBoolean(value);
                }

                if (options.TryGetValue("cache_wsdl", out value))
                {
                    wsdlCache = (WsdlCache)value;//PHP.Core.Convert.ObjectToBoolean(value);//WsdlCache.None == 0, anything else is true
                }

                if (options.TryGetValue("exceptions", out value))
                {
                    exceptions = PHP.Core.Convert.ObjectToBoolean(value);
                }

                if (options.TryGetValue("soap_version", out value))
                {
                    version = (SoapVersion) PHP.Core.Convert.ObjectToInteger(value);
                }

                // certificate:
                string pass = null;

                if (options.TryGetValue("passphrase", out value))
                {
                    pass = Core.Convert.ObjectToString(value);
                }

                if (options.TryGetValue("local_cert", out value))
                {
                    var cert = Core.Convert.ObjectToString(value);
                    if (cert != null)
                        certificate = new X509Certificate2(cert, pass, X509KeyStorageFlags.MachineKeySet);
                }
            }

            try
            {
                wsp = new DynamicWebServiceProxy(wsdl, enableMessageAccess, wsdlCache, certificate, version);
            }
            catch (Exception exception)
            {
                SoapFault.Throw(ScriptContext.CurrentContext, "SOAP-ERROR", exception.Message, exceptions);
            }

        }
        /// <summary>
        /// Set the SOAP version according to the SoapVersion property.
        /// </summary>
        /// <param name="dwsSoap">set meeting proxy</param>
        private void SetSoapVersion(DwsSoap dwsSoap)
        {
            this.soapVersion = Common.GetConfigurationPropertyValue<SoapVersion>("SoapVersion", this.Site);

            if (this.soapVersion == SoapVersion.SOAP11)
            {
                dwsSoap.SoapVersion = SoapProtocolVersion.Soap11;
            }
            else if (this.soapVersion == SoapVersion.SOAP12)
            {
                dwsSoap.SoapVersion = SoapProtocolVersion.Soap12;
            }
            else
            {
                Site.Assume.Fail(
                    "Property SoapVersion value must be {0} or {1} at the ptfconfig file.",
                    SoapVersion.SOAP11.ToString(),
                    SoapVersion.SOAP12.ToString());
            }
        }