示例#1
0
        public void SendToWS_SOAP(string url, string method, string service, string xml)
        {
            this.serviceContext.Services.SingleOrDefault(key => key.Key == service).Value.Should()
            .BeNull($"Сервис с названием '{service}' уже существует");
            url.Should().NotBeEmpty("Ссылка на сервис не задана");
            method.Should().NotBeEmpty("Метод сервиса не задан");
            xml.Should().NotBeEmpty("Запрос к сервису не задан");

            url    = this.variableContext.ReplaceVariablesInXmlBody(url, (val) => System.Security.SecurityElement.Escape(Reflection.ConvertObject <string>(val)));
            method = this.variableContext.ReplaceVariablesInXmlBody(method, (val) => System.Security.SecurityElement.Escape(Reflection.ConvertObject <string>(val)));
            xml    = this.variableContext.ReplaceVariablesInXmlBody(xml, (val) => System.Security.SecurityElement.Escape(Reflection.ConvertObject <string>(val)));

            this.consoleOutputHelper.WriteLine($"url (сериализован): {url}");
            this.consoleOutputHelper.WriteLine($"Запрос (сериализован): {Environment.NewLine}{xml}");
            using (var soap = new Soap(url, method))
            {
                var(statusCode, errors) = soap.CallWebService(xml);

                this.serviceContext.Services.Add(service, new WebService()
                {
                    Url  = url,
                    Body = xml,
                    HeadersCollection    = soap.Headers,
                    ParametersCollection = null,
                    Service    = (Core.Data.Services.Service)soap.Clone(),
                    StatusCode = statusCode,
                    Errors     = errors,
                });
            }
        }