Now with SMS ! New
or create new account
Anveo API - C# Code Sample


C# code sample for Anveo® API integration.
using System;
using System.Xml;
using System.Net;
using System.IO;
using System.Security.Cryptography;

/// <summary>
///--------------------------------------------------------------------------------------------------------
///              .NET C# implementation of Anveo API to initiate DIAL.CONNECT API function
///
///   The rest of Anveo API functions can be implemented by simply changing XML stored in $data variable
///                                          2008 - Anveo team.
///--------------------------------------------------------------------------------------------------------
/// </summary>

Public static string GetSignature(String email, String passphrase) {
	var enc = Encoding.ASCII;
	HMACSHA1 hmac = new HMACSHA1(enc.GetBytes(passphrase));
	hmac.Initialize();
	byte[] buffer = enc.GetBytes(email);
	return BitConverter.ToString(hmac.ComputeHash(buffer)).Replace("-", "").ToLower();
}

public static XmlDocument doApiCall(String sApiXML)
{
	//Declare XMLResponse document
	XmlDocument XMLResponse = null;

	//Declare an HTTP-specific implementation of the WebRequest class.
	HttpWebRequest objHttpWebRequest;

	//Declare an HTTP-specific implementation of the WebResponse class
	HttpWebResponse objHttpWebResponse = null;

	//Declare a generic view of a sequence of bytes
	Stream objRequestStream = null;
	Stream objResponseStream = null;

	//Declare XMLReader
	XmlTextReader objXMLReader;

	//Creates an HttpWebRequest for the Anveo API URL.
	objHttpWebRequest = (HttpWebRequest)WebRequest.Create("https://www.anveo.com/api/v3.asp");


	try
	{
		//---------- ANVEO API HttpRequest

		//Prepare HttpWebRequest properties
		byte[] bytes;
		bytes = System.Text.Encoding.ASCII.GetBytes(sApiXML);
		objHttpWebRequest.Method = "POST";
		objHttpWebRequest.ContentLength = bytes.Length;
		objHttpWebRequest.ContentType = "application/xml; encoding='utf-8'";
		objHttpWebRequest.Accept="application/xml; encoding='utf-8'";

		//Get Stream object
		objRequestStream = objHttpWebRequest.GetRequestStream();

		//Writes a sequence of bytes to the current stream
		objRequestStream.Write(bytes, 0, bytes.Length);

		//Close stream
		objRequestStream.Close();

		//Send and wait for a response.
		objHttpWebResponse = (HttpWebResponse)objHttpWebRequest.GetResponse();

		//---------- End ANVEO API HttpRequest

		//---------- ANVEO API HttpResponse
		if (objHttpWebResponse.StatusCode == HttpStatusCode.OK)
		{
			//Get response stream
			objResponseStream = objHttpWebResponse.GetResponseStream();

			//Load response stream into XMLReader
			objXMLReader = new XmlTextReader(objResponseStream);

			//Declare XMLDocument
			XmlDocument xmldoc = new XmlDocument();
			xmldoc.Load(objXMLReader);

			//Set XMLResponse object returned from XMLReader
			XMLResponse = xmldoc;

			//Close XMLReader
			objXMLReader.Close();
		}

		//Close HttpWebResponse
		objHttpWebResponse.Close();
	}
	catch (WebException we)
	{
		//TODO: Add exception handling
		throw new Exception(we.Message);
	}
	catch (Exception ex)
	{
		throw new Exception(ex.Message);
	}
	finally
	{
		//Close connections
		objRequestStream.Close();
		objResponseStream.Close();
		objHttpWebResponse.Close();
	}

	return XMLResponse;
}
		
...
...
...

String sApiXml= @"<?xml version=""1.0"" standalone=""no"" ?>
<REQUEST>
	<USERTOKEN>
		<USERKEY>----------- YOUR API USERKEY -----------</USERKEY>
	</USERTOKEN>
	<ACTION NAME=""DIAL.CONNECT"">
		<PARAMETER NAME=""SIGNATURE"">SOMESIGNATURE</PARAMETER>
		<PARAMETER NAME=""TEST"">TRUE</PARAMETER>
		<PARAMETER NAME=""PHONENUMBER"">1215215215</PARAMETER>
		<PARAMETER NAME=""DESTPHONENUMBER"">1212121212</PARAMETER>
		<PARAMETER NAME=""CALLERID"">12157010680</PARAMETER>
		<PARAMETER NAME=""DELAY"">1440</PARAMETER>
		<PARAMETER NAME=""MEMO"">DIAL.CONNECT API Action example to connect 1215215215 with 1212121212 delayed by 24 hours</PARAMETER>
	</ACTION>
</REQUEST>";

XmlDocument ApiXMLResponse = null;
ApiXMLResponse=doApiCall(sApiXml);
//System.Console.WriteLine(ApiXMLResponse.InnerXml);

...
...
...

		
:.:
News Blog About Anveo Terms of Use FAQ Contact Us © 2017 Anveo Inc.