Can I call REST web services from Windows Mobile a

2019-08-19 01:34发布

问题:

I would like to build a simple REST web service (using Ruby on Rails). However, I would like to be able to call this service from a Windows mobile app. Is that possible? or do I have to use SOAP?

I don't have much experience with Windows Mobile apps so it would be nice if you can provide pseudo code or link to tutorial for the possible case.

Thanks,

Tam

回答1:

Yes you can. I've done it lots using the Win32 wininet API.

You can also do it in C# using the System.Net HttpWebRequest API.



回答2:

 dim sendUrl : sendUrl = baseUrl & url
 dim objXML : Set objXML = CreateObject("MSXML2.ServerXMLHTTP.6.0")

 objXML.open "GET", sendUrl, false

 objXML.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
 objXML.send(sendxml)

 HttpPost = objXml.responseText

 Set objXML = nothing

On desctop Microsoft offers an com interface which can be used to implement REST APIs. Maybe this also exists on Windows Mobile.



回答3:

Here's an example of using a HttpWebRequest to call the twitter search api,hth:

Uri uri = new Uri("http://search.twitter.com/search.json?q=twitter");
String result = String.Empty;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
    using (Stream responseStream = response.GetResponseStream())
    {
        using (StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8))
        {
            result = readStream.ReadToEnd();
        }
    }
}