« Back to Extension Mobility API Questions

RE: Extension Mobility Query...

Combination View Flat View Tree View
Threads [ Previous | Next ]
 
Hey guys,

I'm just trying to execute a query using EMAPI...
 
heres the Code...
 
       ExtQuery = "<query>/n";
                ExtQuery += "<appInfo> /n";
                ExtQuery += "<appID>admin</appID> /n";
                ExtQuery += "<appCertificate>p1tBas!c</appCertificate> /n";
                ExtQuery += "</appInfo> /n";
                ExtQuery += "<userDevicesQuery> /n";
                ExtQuery += "<userID>" + UserID + "</userID> /n";
                ExtQuery += "</userDevicesQuery> </query>/n";        
 

 
   HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://192.168.200.15/emservice/EMServiceServlet");
 

   req.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
            req.ContentType = "application/x-www-form-urlencoded";
            req.Method = "POST";
            req.KeepAlive = true; 
 
            Stream s = req.GetRequestStream();
            s.Write(System.Text.Encoding.ASCII.GetBytes(ExtQuery), 0, ExtQuery.Length);
            s.Close();
            WebResponse resp = req.GetResponse();
            StreamReader sr = new StreamReader(resp.GetResponseStream());
            string XMLResult = sr.ReadToEnd();
 
Im getting an Error 500 Internal server error...
 
does anyone have any suggestions? if i browse to the URL i also get an error 500 page.
 
Dan


 

Hi,
 
I've seen this error before. For us the solution was to enable Extension Mobility on BOTH publisher and subscriber. If it was enabled for only one of them it gave http 500 error.
 
Hope this helps.
 
 

very odd...
 
there must be multiple causes for this then!!!
 
i only have a publisher.. its a vmware test machine...
 
anyhoo i think it was my headers...
 
In case anyone is curious I got it working with this:
 

   ExtQuery = "xml=<query>";
                ExtQuery += "<appInfo> <appID>admin</appID> <appCertificate>p1tBas!c</appCertificate> </appInfo>";
                ExtQuery += "<userDevicesQuery> <userID>"+UserID+"</userID> </userDevicesQuery>";
                ExtQuery += "</query>";

 

       HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://x.x.x.x:8080/emservice/EMServiceServlet");
 
            req.Accept = "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2";
            req.ContentType = "application/x-www-form-urlencoded";
            req.Method = "POST";
            req.KeepAlive = true;
 
            Stream s = req.GetRequestStream();
            s.Write(System.Text.Encoding.ASCII.GetBytes(ExtQuery), 0, ExtQuery.Length);
            s.Close();
            WebResponse resp = req.GetResponse();
            StreamReader sr = new StreamReader(resp.GetResponseStream());
            string XMLResult = sr.ReadToEnd();

Sorry Michael, I meant to say thanks for the suggestion too!!!
 
this forum seems awfully quiet so I wasn't really expecting a response.
 
Dan

may you say how to work this services on IP phones??
userid ,machine id e.g values how to take??

Hi Dan,
 
I ran into the same problem with CUCM 6.1.2 (on VMWare too).
While my C# doesn't work a simple HTML works.
 
Did you find any solution?
 
Kind regards
 
Axel

Hi Dan,
 
I think I found "your" fault ... it isn't really yours, it is more to the developer or those who write the documentation.
1. Although you might think we are talking XML, no, we don't. That means no xml header like <?xml version=1.0> etc. Just use simple string.
2. urlencode the xml based em api call "urlencode("<query>...some content ...</query>");"
3. prepend an xml= (not urlencode!) to encoded xml (see step 2).
4. use HTTP header "Content-Type: application/x-www-form-urlencoded"
 
that should work. In your example you miss step 3 I think.
 
Kind reagards
 
Axel

cool, I couldn't find the "Content-Type: application/x-www-form-urlencoded" in the API doco, very odd that this is used...
I had to run wireshark to trace the message from the EMApi example to see the header..
a REST service would have been nice, like CUPI, Cisco introduced too many different webservices ;-)