You are not Logged in
Would you like to Login or Register

Today is: Friday, 21 November, 2008
Check this months hot topics

Authenticated HTTPRequests (Using Credentials)

Recently I had to make a SOAP call to a Cisco CallManager (an IP PBX). This required that the request used basic authentication. I couldn't add a web reference as the cisco interface doesn't support GET requests, so the Visual Studio discovery fails - even after authenticating.

It turns out that making a call to a webService is not too hard anyway and adding the credentials is just a single extra line of code, as shown in the sample below...

string axlrequest = "listPhoneByDescription";
string axlparameters = "<searchString>%Build%</searchString>";

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://ccmivr/CCMApi/AXL/V1/soapisapi.dll");        
req.Credentials = new NetworkCredential("myLogin""myPwd"); //This line ensures the request is processed through Basic Authentication

req.ContentType = "text/xml";
req.Method = "POST";
req.Accept = "text/xml";

Stream s = req.GetRequestStream();

string soaprequest;
soaprequest = "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2000/10/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\">\n";
soaprequest += "<SOAP-ENV:Body>\n";
soaprequest += "<axl:" + axlrequest + " xmlns:axl=\"http://www.cisco.com/AXL/1.0\" xsi:schemaLocation=\"http://www.cisco.com/AXL/1.0 http://gkar.cisco.com/schema/axlsoap.xsd\" xsi:type=\"XRequest\" sequence=\"1234\">\n";
soaprequest += axlparameters + "\n";
soaprequest += "</axl:" + axlrequest + ">\n";
soaprequest += "</SOAP-ENV:Body>\n";
soaprequest += "</SOAP-ENV:Envelope>";

s.Write(System.Text.Encoding.ASCII.GetBytes(soaprequest),0,soaprequest.Length );

s.Close();

WebResponse resp = req.GetResponse();
StreamReader sr = new StreamReader (resp.GetResponseStream());
Response.ContentType = "text/xml";
Response.Write(sr.ReadToEnd()); //Just output XML response

This example uses the Cisco AXL interface to request a list of phones that match the description.

kick it on DotNetKicks.com del.icio.us digg Mister Wong YahooMyWeb Reddit Furl Spurl blogmarks
Dave Howard Skype
Author : Dave Howard
Published : Monday, 04 September, 2006

I have been involved in IT development for the last 10 years - a lot of it around desktop applications and telecoms.

Add Comment

Enter your comment below and it will be submitted for moderation.

Your Name

Add Tag

Please enter tags for this article, seperated by semi-colon ;

View Tag's by : # articles | # views