GeekZilla
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.
I have been involved in IT development for the last 10 years - a lot of it around desktop applications and telecoms.
Comments
anonymous said:
very helpful post!
Josh Kunken said:
you're missing something along the lines of:
req.Headers.Add(String.Format("SOAPAction: \"{0}\"",
operationName));
placed underneath the following:
req.Accept = "text/xml";
then it works fine.
ExSter said:
Hello,
Could you explain me how to use your partial code in a ASP.NET page to try to obtain information throught CallManager with AXL?
Thanks.
Hi, said:
Can u tell me about how to call web service without add web referent via ASP.Net..Web Service has authorization..