.NET Core 中的 SoapHttpClientProtocol 等效项

Dav*_*May 14 c# soap web-services .net-core

我正在尝试从 .NET Core 调用肥皂网络服务。

我使用构建了代理dotnet-svcutil,发现它与同一端点的旧版 .NET 4.6 实现有很大不同。

.NET Core 代理没有继承自System.Web.Services.Protocols.SoapHttpClientProtocol. 我知道这个命名空间在 .NET Core 中已经消失了,但是什么取代了它呢?

小智 0

我的建议是要求该服务的制造商创建一项能够大肆宣传的新服务。我最近不得不消费肥皂服务,遇到各种特价商品。决定跳过 core.net 中已实现的一半肥皂,并使用带有肥皂信封的简单发布请求来调用它。您可以使用 wsdl 来制作需要序列化为 xml 的类。(在 VS 中使用粘贴 xml 作为类!)

 private async Task<EnvelopeBody> ExecuteRequest(Envelope request)
    {
        EnvelopeBody body = new EnvelopeBody();
        var httpWebRequest = new HttpRequestMessage(HttpMethod.Post, _serviceUrl);
        string soapMessage = XmlSerializerGeneric<Envelope>.Serialize(request);

        httpWebRequest.Content = new StringContent(soapMessage);

        var httpResponseMessage = await _client.SendAsync(httpWebRequest);
        if (httpResponseMessage.IsSuccessStatusCode)
        {
            using var contentStream = await httpResponseMessage.Content.ReadAsStreamAsync();
            Envelope soapResult;
            var mySerializer = new XmlSerializer(typeof(Envelope));
            using (StreamReader streamReader = new StreamReader(contentStream))
            {
                soapResult = (Envelope) mySerializer.Deserialize(streamReader);
            }
            body = soapResult.Body;
        }
        return body;
    }

My soap envelope looks like this:

   [System.SerializableAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "http://schemas.xmlsoap.org/soap/envelope/", IsNullable = false)]
    public partial class Envelope
    {
        private object headerField;

        private EnvelopeBody bodyField;

        /// <remarks/>
        public object Header
        {
            get
            {
                return this.headerField;
            }
            set
            {
                this.headerField = value;
            }
        }

        /// <remarks/>
        public EnvelopeBody Body
        {
            get
            {
                return this.bodyField;
            }
            set
            {
                this.bodyField = value;
            }
        }
    }

Run Code Online (Sandbox Code Playgroud)