-
Notifications
You must be signed in to change notification settings - Fork 23
Tutorial
- Installing Simple SOAP Client
- SOAP Envelopes
- Creating SOAP Envelope Body
- Creating SOAP Envelope Headers
Simple SOAP Client can be installed via NuGet packages. Just run the following command in your project or search for it in Visual Studio NuGet package explorer:
Install-Package SimpleSOAPClient -PreThe currently recommended version to install is 2.0.0-rc03 or greater, even in its release candidate state. Older and stable versions should work as expected (1.2.2) but a major improvement was made in releases 2.x, specially in the handlers pipeline logic.
This library provides a way to send SOAP Envelopes using the HTTP protocol. These objects are serialized to their XML representations using attributes and classes present in the System.Xml.Serialization and System.Xml.Linq namespaces. This should be extensible enough to create any XML representation of a given SOAP body or header to the developer needs.
To create SOAP Envelopes you can either create an instance new SoapEnvelope() or use the helper method SoapEnvelope.Prepare().
To create a type that can be included or read from the SOAP Envelope body, the only requirement is to have the XmlRoot attribute. Here are some examples:
[XmlRoot("CreateUserRequest", Namespace = "http://services.company.com")]
public class CreateUserRequest
{
[XmlElement("Username")]
public string Username { get; set; }
[XmlElement("Password")]
public string Password { get; set; }
}
[XmlRoot("CreateUserResponse", Namespace = "http://services.company.com")]
public class CreateUserResponse
{
[XmlElement("Suceeded")]
public bool Suceeded { get; set; }
}To assign or read the object to and from the SOAP Envelope body, the easiest way is to use the helper methods EnvelopeHelpers.Body overloads. Example:
var envelope = SoapEnvelope.Prepare();
envelope.Body(new CreateUserRequest());
var request = envelope.Body<CreateUserRequest>();To create a type that can be included or read as a SOAP Envelope header, it must have XmlRoot attribute and extend from the SoapHeader class (extending is not a requirement, but helps keeping with the standard). Here are some examples:
[XmlRoot("Tracking", Namespace = "http://services.company.com")]
public class TrackingHeader : SimpleSOAPClient.Models.SoapHeader
{
[XmlElement("Id")]
public Guid Id { get; set; }
[XmlElement("CreatedOn")]
public DateTime CreatedOn { get; set; }
public TrackingHeader()
{
MustUnderstand = 0; // this is the default value
}
}To assign or read the object to and from the SOAP Envelope header, the easiest way is to use the helper methods EnvelopeHelpers.WithHeaders overloads. Example:
var envelope = SoapEnvelope.Prepare();
envelope.WithHeaders(new TrackingHeader());
var header = envelope.Header<TrackingHeader>("{http://services.company.com}Tracking");