Skip to content

Repository files navigation

Simple SOAP Client

Lightweight SOAP client for invoking HTTP SOAP endpoints. Fluently create SOAP Envelopes, send them through the SOAP Client and extract the needed information from the returned SOAP Envelope. The client also exposes a range of handler that can be used as a pipeline to work with the SOAP Envelope or the HTTP requests and responses.

Buy Me A Coffee

Installation

This library can be installed via NuGet package. Just run the following command:

Install-Package SimpleSOAPClient

Compatibility

This library is compatible with the folowing frameworks:

  • .NET Framework 4.5
  • .NET Standard 1.1
  • .NET Standard 2.0
  • UAP 10.0

Usage

publicstaticasyncTaskMainAsync(string[]args,CancellationTokenct){using(varclient=SoapClient.Prepare().WithHandler(newDelegatingSoapHandler{OnSoapEnvelopeRequestAsyncAction=async(c,d,cancellationToken)=>{d.Envelope.WithHeaders(KnownHeader.Oasis.Security.UsernameTokenAndPasswordText("some-user","some-password"));},OnHttpRequestAsyncAction=async(soapClient,d,cancellationToken)=>{Logger.LogTrace("SOAP Outbound Request -> {0} {1}({2})\n{3}",d.Request.Method,d.Url,d.Action,awaitd.Request.Content.ReadAsStringAsync());},OnHttpResponseAsyncAction=async(soapClient,d,cancellationToken)=>{Logger.LogTrace("SOAP Outbound Response -> {0}({1}) {2} {3}\n{4}",d.Url,d.Action,(int)d.Response.StatusCode,d.Response.StatusCode,awaitd.Response.Content.ReadAsStringAsync());},OnSoapEnvelopeResponseAsyncAction=async(soapClient,d,cancellationToken)=>{varheader=d.Envelope.Header<UsernameTokenAndPasswordTextSoapHeader>("{"+Constant.Namespace.OrgOpenOasisDocsWss200401Oasis200401WssWssecuritySecext10+"}Security");}})){varrequestEnvelope=SoapEnvelope.Prepare().Body(newIsAliveRequest());SoapEnveloperesponseEnvelope;try{responseEnvelope=awaitclient.SendAsync("https://services.company.com/Service.svc","http://services.company.com/IService/IsAlive",requestEnvelope,ct);}catch(SoapEnvelopeSerializationExceptione){Logger.LogError(e,$"Failed to serialize the SOAP Envelope [Envelope={e.Envelope}]");throw;}catch(SoapEnvelopeDeserializationExceptione){Logger.LogError(e,$"Failed to deserialize the response into a SOAP Envelope [XmlValue={e.XmlValue}]");throw;}try{varresponse=responseEnvelope.Body<IsAliveResponse>();}catch(FaultExceptione){Logger.LogError(e,$"The server returned a fault [Code={e.Code}, String={e.String}, Actor={e.Actor}]");throw;}}}[XmlRoot("IsAliveRequest",Namespace="http://services.company.com")]publicclassIsAliveRequest{}[XmlRoot("IsAliveResponse",Namespace="http://services.company.com")]publicclassIsAliveResponse{[XmlElement("IsAliveResult")]publicboolIsAlive{get;set;}}

About

Lightweight SOAP client for invoking HTTP SOAP endpoints

Resources

Stars

80 stars

Watchers

11 watching

Forks

Releases

Packages

Used by

Contributors

Languages