SoapHttpClient 3.0.0

dotnet add package SoapHttpClient --version 3.0.0                
NuGet\Install-Package SoapHttpClient -Version 3.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SoapHttpClient" Version="3.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SoapHttpClient --version 3.0.0                
#r "nuget: SoapHttpClient, 3.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SoapHttpClient as a Cake Addin
#addin nuget:?package=SoapHttpClient&version=3.0.0

// Install SoapHttpClient as a Cake Tool
#tool nuget:?package=SoapHttpClient&version=3.0.0                

SoapHttpClient NuGet

A lightweight wrapper of an HttpClient (using IHttpClientFactory) for POSTing messages that allows the user to send the SOAP Body and Header (if needed) without caring about the envelope.

Changelog

3.0.0

  • Replaced HttpClient with HttpClientFactory.

2.2.1

  • Added support for Cancellation Tokens.

2.2.0

  • Updated codebase.
  • Migrated test project to .net core app.
  • Fixed an error of SOAPAction not being sent.

2.1.0

  • Updated to NetStandardLibrary 2.0
  • Fixed a bug where an extension method was calling himself recursively

2.0.0

  • Major refactor to the codebase.
  • Added the functionality of adding more than one header and/or body in the envelope.
  • The ctor will no longer determine the SoapVersion, since it is a message property and the API should be ignorant about this.
  • [BREAKING CHANGE]: SoapVersion is now required for every message.
  • [BREAKING CHANGE]: Removed methods where the endpoint was a string instead of an uri.

API

Constructors

SoapClient()

Initializes SoapClient with a default IHttpClientFactory that implements automatic decompression.

SoapClient(IHttpClientFactory httpClientFactory)

Initializes SoapClient with a IHttpClientFactory provided by the caller. The IHttpClientFactory is the new interface used to manage HttpClient introduced on .NET Core 2.1.


Methods

All Methods and Extension Methods returns a Task of HttpResponseMessage

The interface makes the client implement the following method:

Task<HttpResponseMessage> PostAsync(
	Uri endpoint,
	SoapVersion soapVersion,
	IEnumerable<XElement> bodies,
	IEnumerable<XElement> headers = null,
	string action = null,
	CancellationToken cancellationToken = CancellationToken.Default);

Allowing us to send the following calls:

  • Uri / Version / Bodies
  • Uri / Version / Bodies / Headers
  • Uri / Version / Bodies / Headers / Action

Then there are sugar sintax extension methods:

Task<HttpResponseMessage> PostAsync(
	this ISoapClient client,
	Uri endpoint,
	SoapVersion soapVersion,
	XElement body,
	XElement header = null,
	string action = null,
	CancellationToken cancellationToken = CancellationToken.Default);

Task<HttpResponseMessage> PostAsync(
	this ISoapClient client,
	Uri endpoint,
	SoapVersion soapVersion,
	IEnumerable<XElement> bodies,
	XElement header,
	string action = null,
	CancellationToken cancellationToken = CancellationToken.Default);

Task<HttpResponseMessage> PostAsync(
	this ISoapClient client,
	Uri endpoint,
	SoapVersion soapVersion,
	XElement body,
	IEnumerable<XElement> headers,
	string action = null,
	CancellationToken cancellationToken = CancellationToken.Default);

Allowing us to send the following calls:

  • Uri / Version / Body
  • Uri / Version / Body / Header
  • Uri / Version / Body / Header / Action
  • Uri / Version / Bodies / Header
  • Uri / Version / Bodies / Header / Action
  • Uri / Version / Body / Headers
  • Uri / Version / Body / Headers / Action

With all of these variants we can send a message with:

  • 1 Body - 1 Header
  • 1 Body - N Headers
  • N Bodies - 1 Header
  • N Bodies - N Headers

There are also extension methods for sync calls: However we always recommend using async programming when you are able.

Their method name is Post and their return type is HttpResponseMessage

Finally, we have extensions methods for using bodies and headers as objects and using serialization the default or a custom IXElementSerializer to serialize those objects to XElement.

Usage Examples

Controlling the Media Type

As the SoapHttpClient wraps a HttpClient you can control all aspects of the HTTP Request using a HttpMessageHandler:

public class ContentTypeChangingHandler : DelegatingHandler
{
  public ContentTypeChangingHandler(HttpMessageHandler innerHandler) : base(innerHandler) { }

  protected async override Task<HttpResponseMessage> SendAsync(
    HttpRequestMessage request,
    CancellationToken cancellationToken)
  {
    request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("text/xml; charset=utf-8");
    return await base.SendAsync(request, cancellationToken);
  }
}

Call NASA

async Task CallNasaAsync()
{
    var soapClient = new SoapClient();
    var ns = XNamespace.Get("http://helio.spdf.gsfc.nasa.gov/");

    var result =
        await soapClient.PostAsync(
            new Uri("http://sscweb.gsfc.nasa.gov:80/WS/helio/1/HeliocentricTrajectoriesService"),
            SoapVersion.Soap11,
            body: new XElement(ns.GetName("getAllObjects")));

    result.StatusCode.Should().Be(HttpStatusCode.OK);
}
Result of Calling NASA Heliocentric Trajectories Service
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:getAllObjectsResponse xmlns:ns2="http://helio.spdf.gsfc.nasa.gov/">
         <return>
            <endDate>1993-01-01T00:00:00Z</endDate>
            <id>0001</id>
            <name>COMET GRIGG-SKJLP</name>
            <startDate>1992-01-01T00:00:00Z</startDate>
         </return>
         <return>
            <endDate>1996-03-02T00:00:00Z</endDate>
            <id>0002</id>
            <name>COMET H-M-P</name>
            <startDate>1996-01-01T00:00:00Z</startDate>
         </return>
         <return>
            <endDate>1997-12-31T00:00:00Z</endDate>
            <id>0003</id>
            <name>COMET HALE-BOPP</name>
            <startDate>1997-01-01T00:00:00Z</startDate>
         </return>
         .
         .
         .
      </ns2:getAllObjectsResponse>
   </S:Body>
</S:Envelope>

Soap Icon Created by Jakob Vogel from the Noun Project

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on SoapHttpClient:

Package Downloads
ACO.Components

Helpers used in ACO 2.0

NetXP.NetStandard.Network.Services.Implementations

Soap Implementations Of NetXP.NetStandard.Network Interfaces.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on SoapHttpClient:

Repository Stars
BAndysc/WoWDatabaseEditor
Integrated development environment (IDE), an editor for Smart Scripts (SAI/smart_scripts) for TrinityCore based servers. Cmangos support work in progress. Featuring a 3D view built with OpenGL and custom ECS framework
Version Downloads Last updated
3.0.0 305,667 6/2/2019
2.2.1 161,142 10/9/2018
2.2.0 3,750 7/19/2018
2.1.0 24,055 8/25/2017
2.0.0 4,553 7/3/2017
1.4.3 5,758 11/29/2016

- 3.0.0
   -- Replaced HttpClient with HttpClientFactory
   - 2.2.1
   -- Added support for Cancellation Tokens.
   - 2.2.0
   -- Updated codebase.
   -- Migrated test project to .net core app
   -- Fixed an error of SOAPAction not being sent.
- 2.1.0
-- Updated to NetStandardLibrary 2.0
-- Fixed a bug where an extension method was calling himself recursively
- 2.0.0
-- Major refactor to the codebase.
-- Added the functionality of adding more than one header and/or body in the envelope.
-- The ctor will no longer determine the SoapVersion, since it is a message property and the API should be ignorant about this.
-- BREAKING CHANGE: SoapVersion is now required for every message.
-- BREAKING CHANGE: Removed methods where the endpoint was a string instead of an uri.