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.
This library can be installed via NuGet package. Just run the following command:
Install-Package SimpleSOAPClientThis library is compatible with the folowing frameworks:
- .NET for Windows Store apps (> .NETCore 4.5);
- .NET Framework 4.0
- .NET Framework 4.5
- .NET Platform (> DotNET 5.0)
- DNX Core (> DNXCore 5.0)
publicstaticasyncTaskMainAsync(string[]args,CancellationTokenct){using(varclient=SoapClient.Prepare().OnSerializeRemoveXmlDeclaration().UsingRequestEnvelopeHandler((c,d)=>{d.Envelope.WithHeaders(KnownHeader.Oasis.Security.UsernameTokenAndPasswordText("some-user","some-password"));}).UsingRequestRawHandler((c,d)=>{Logger.Trace("SOAP Outbound Request -> {0} {1}({2})\n{3}",d.Request.Method,d.Url,d.Action,d.Content);}).UsingResponseRawHandler((c,d)=>{Logger.Trace("SOAP Outbound Response -> {0}({1}) {2} {3}\n{4}",d.Url,d.Action,(int)d.Response.StatusCode,d.Response.StatusCode,d.Content);}).UsingResponseEnvelopeHandler((c,d)=>{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.Error(e,$"Failed to serialize the SOAP Envelope [Envelope={e.Envelope}]");throw;}catch(SoapEnvelopeDeserializationExceptione){Logger.Error(e,$"Failed to deserialize the response into a SOAP Envelope [XmlValue={e.XmlValue}]");throw;}try{varresponse=responseEnvelope.Body<IsAliveResponse>();}catch(FaultExceptione){Logger.Error(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;}}