.NET Wrapper for Text Messaging API
XmlService.cs
- This class inherits from RESTService to work on REST services that use XML as the POST language.
< Previous |
Home |
Next >
#region Using Statements
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Xml;
#endregion
namespace TxtSignal.CoreServices
{
/// <summary>
/// ******************************************************************
/// * *
/// * This code was written by your good friends at SplashTone.com. *
/// * This code is offered freely in the spirit of knowledge sharing.*
/// * If you find good use out of it, check out our site and maybe *
/// * drop us a line (support@splashtone.com)! *
/// * *
/// * SplashTone.com is a site for booking bands online. *
/// * SplashTone.com is run by OpenBracketLLC.com. *
/// * *
/// ******************************************************************
///
/// Provides a mechanism for accessing web services implemented over a simple
/// XML interface (http/s gets and posts with xml data). Consumers may either
/// inherit from this class or simply use it in its regular form.
/// </summary>
public class XmlService : RESTService
{
#region Members and Constructors
protected XmlDocument _requestXml;
protected XmlDocument _responseXml;
public XmlService() : base()
{
_requestXml = new XmlDocument();
AddXmlDeclaration();
}
public XmlService(string serviceUrl) : base(serviceUrl)
{
_requestXml = new XmlDocument();
AddXmlDeclaration();
}
#endregion
#region Properties
/// <summary>
/// Gets or sets the response as an XmlDocument.
/// </summary>
public XmlDocument ResponseXml
{
get { return _responseXml; }
}
/// <summary>
/// Gets or sets the xml to send to the service.
/// </summary>
public XmlDocument RequestXml
{
get { return _requestXml; }
set { _requestXml = value; }
}
public override bool UsePostMethod
{
get { return true; }
set
{
throw new NotSupportedException();
}
}
#endregion
#region Overrides and Methods
/// <summary>
/// Adds the standard xml declaration to this xml document.
/// </summary>
protected void AddXmlDeclaration()
{
XmlDeclaration xDeclare = _requestXml.CreateXmlDeclaration("1.0", null, null);
_requestXml.AppendChild(xDeclare);
}
protected override string GetParameterData()
{
return _requestXml.OuterXml;
}
protected override HttpWebRequest CreateRequest(string dataToSend)
{
HttpWebRequest request = base.CreateRequest(dataToSend);
request.ContentType = "text/xml";
return request;
}
protected override void OnSuccess()
{
base.OnSuccess();
_responseXml = new XmlDocument();
_responseXml.LoadXml(Response);
}
#endregion
}
}
< Previous |
Home |
Next > Send any comments or questions here and we will do our best to respond!
support@splashtone.com.
Bored? Check out
our blog.