13

I'm trying to invoke a soap web service from .NET Core.

I've built the proxy using dotnet-svcutil and found it's a lot different from an older .NET 4.6 implementation of the same endpoint.

The .NET Core proxy doesn't have a class that inherits from System.Web.Services.Protocols.SoapHttpClientProtocol. I understand this namespace is gone in .NET Core, but what has replaced it?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
David May
  • 368
  • 3
  • 10
  • Does this answer your question ? : https://stackoverflow.com/questions/48625444/calling-a-soap-service-in-net-core – mabiyan Jun 28 '21 at 17:36

1 Answers1

0

My advise is to ask for the maker of the service to create a new service that talks swagger. I recently had to consume a soap service, ran into all kinds of specials. Decided to skip the half implemented soap in core.net and called it using a simple post request with a soap envelope in it. You can use the wsdl to craft your classes you need to serialize to xml. (use paste xml as classes in VS!)

 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;
            }
        }
    }

Jeroen
  • 9
  • 3