首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SoapHttpClientProtocol等效于.NET核

SoapHttpClientProtocol等效于.NET核
EN

Stack Overflow用户
提问于 2021-06-28 14:49:10
回答 1查看 2.3K关注 0票数 12

我试图从.NET核心调用soap服务。

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

.NET核心代理没有继承自System.Web.Services.Protocols.SoapHttpClientProtocol的类。我知道这个名称空间在.NET核心中消失了,但是是什么取代了它呢?

EN

回答 1

Stack Overflow用户

发布于 2022-11-16 16:25:13

我的建议是请该服务的制造者创建一项新的服务,该服务可以夸夸其谈。最近我不得不使用一个soap服务,遇到了各种各样的特色菜。决定跳过core.net中半实现的soap,并使用带有soap信封的简单post请求调用它。您可以使用wsdl来创建您需要序列化为xml的类。(在VS中使用粘贴xml作为类)

代码语言:javascript
复制
 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;
            }
        }
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68165488

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档