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

WCF Consuming

$
0
0

I am not being able to accomplish a the consuming of the WCF service that I created and I don't know what more can I do. I've made a simple service that consists in a connection to my local SQL Server, where I have a database, and then I have another function that makes a simples SELECT query. To test my service, I created a wpf app in visual studio and it all worked ok, so I started creating my Xamarin.Forms app. My goal is to get information from SQL Server in an app that works in both android and ios.
So.. I will tell you exactly what I've done, step by step.

1 - Created a Blank Xaml App (Xamarin.Forms Portable) (already tried a Blank App (without Xaml) and the output is the same.

2 - Uninstalled all NuGet packages (it was just xamarin.forms)

3 - Changed the target (removed windows phones in order to be able to add service references)

4 - Installed Xamarin.Forms (last stable, which is 2.3.0.107)

5 - Added service reference that I created (in my case SQLService.svc) which is hosted in my IIS (I am using noip DUC, that addresses me a host (ex: mycomputer.ddns.net) that is accessible for everyone.

6 - In the MainPage.cs have coded the following:

List lista = new List();
SQLServiceClient client = new SQLServiceClient();

public MainPage()
{
    InitializeComponent();
    labelzita.Text = "ate parece";
    openSqlConnection();
    simpleQuery();

}

private void sqlCompleted(object sender, sqlCompletedEventArgs e)
{
    //lista = e.Result.ToList();
    //labelzita.Text = lista[1].ToString();
    labelzita.Text = e.Result.ToString(); [NOTE THIS LINE PLEASE]
}

private void openSqlConnection()
{
    client.OpenCompleted += openConnectionCompleted;
    client.OpenAsync();
}

private void openConnectionCompleted(object sender, AsyncCompletedEventArgs e)
{
    labelzita.Text = "connection completed";
}

private void simpleQuery()
{
    client.sqlCompleted += sqlCompleted;
    client.sqlAsync();
}

Comments:

I already tried to change the initialization of the client to:

SQLServiceClient client = new SQLServiceClient(new BasicHttpBinding(), new EndpointAddress("http://mycomputer.ddns.net/ikaMobileWebService/SQLService.svc"));

and that did not help me (I think that it is not necessary).

If I don't use the line that I wrote you to note it, the application runs, if I make any reference to e.Result I get an unhandled exception. I am going crazy, this simply does not work and I can't get why!! Another problem is that I have to use my phone to debug since the debugger does not run when I import a web service.

If somebody could help me, I would really appreciate.
Thanks in advance


Viewing all articles
Browse latest Browse all 91519

Trending Articles



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