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=\"\" xmlns:xsi=\"\" xmlns:xsd=\"\">\n";
soaprequest += "<SOAP-ENV:Body>\n";
soaprequest += "<axl:" + axlrequest + " xmlns:axl=\"\" xsi:schemaLocation=\"\" 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 );


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.

Author Dave Howard

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


anonymous said:

very helpful post!

09/Nov/2007 15:51 PM

Josh Kunken said:

you're missing something along the lines of:

req.Headers.Add(String.Format("SOAPAction: \"{0}\"",


placed underneath the following:

req.Accept = "text/xml";

then it works fine.

12/Dec/2007 00:00 AM

ExSter said:


Could you explain me how to use your partial code in a ASP.NET page to try to obtain information throught CallManager with AXL?


18/Feb/2008 11:00 AM

Hi, said:

Can u tell me about how to call web service without add web referent via ASP.Net..Web Service has authorization..

12/Sep/2010 12:22 PM

Add Comment


Your comment has been received and will be shown once it passes moderation.