Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Making HTTP Web Requests

$
0
0

Hello all. I am a brand new xamarin forms user, still on trial. I got a nice email after signing up asking if I need help (which I do) but have yet to get a response. So I am going to outline some issues here!

My goal was to make a "Portable" cross platform app. So far I am writing all of my code in the core app project, and have not much touched the platform specific projects.

I have created some xaml forms, such as an Inventory List. On load, I want to make an HTTP request to get an inventory listing from the server and display it.

Where to find some example code?
http://developer.xamarin.com/guides/cross-platform/application_fundamentals/web_services/
What do you know, a write up on four (4) different ways to make HTTP calls.

First Example: Using HTTPWebRequest

First off, the assemblies required to make the example code even build is not listed. So figure that out first, then build again.

The name 'Console' does not exist in the current context

Fine, I'll remove the outputs, not important anyways, but come on, is this code sample even meant for a cross platform project?

'System.Net.WebRequest' does not contain a definition for 'GetResponse' and no extension method 'GetResponse' accepting a first argument of type 'System.Net.WebRequest' could be found (are you missing a using directive or an assembly reference?)
Oh.....Ok...There is no GetResponse() in the PCL HTTP library..

So unless I am missing something, the first example is rather useless. I tried to implement it using request.BeginGetResponse() but was unsuccessful. Perhaps someone could write up an example of the async style, since that seems to be what we are forced to use.

Second Example: Using RestSharp

RestSharp does not support PCL. Why is it even an example??

Third Example: Using NSUrlConnection

iOS example in the cross platform section. Ok I get that you can write your own platform specific implementations, but this is a silly place to put it.

Fourth Example: ServiceStack Client

OK say I'm willing to pay for this great client.

Install-Package : Could not install package 'ServiceStack.Text 4.0.33'. You are trying to install this package into a project that targets
'portable-net45+win+wp80+MonoAndroid10+xamarinios10+MonoTouch10', but the package does not contain any assembly references or content files that are compatible with that framework

Maybe I am missing something but the examples seem extremely unhelpful.
Here is the only code I have successfully implemented so far, which is very limiting because you cannot pass parameters.

            HttpClient hc = new HttpClient();
            contents = await hc.GetStringAsync(url);
            res = JsonConvert.DeserializeObject<List<string>>(contents);

Help! How can I pass up parameters to a webservice defined like so?

[WebMethod]
public void GetInventory(string searchText)
{
var items = new List();
//some database calls
HttpContext.Current.Response.Write(JsonConvert.SerializeObject(items));
}

Thank you!


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>