UWP with WCF service

I'm try to create the main UWP app to link with the service by perform this step

1.Create Blank App of UWP

2.Create Window Service Application (Create in the solution now the solution will have 2 projects)

3.In the reference in main application Add service reference

4.Discover and then change name of to be something (This time I user ToDoService)

5.Create the code to call in main PS. I'm using the button that create before

    private void button_Click(object sender, RoutedEventArgs e)
    {
        ToDoService.Service1Client client = new ToDoService.Service1Client();
        MessageDialog x = new MessageDialog(client.GetDataAsync(10).Result);
        client.CloseAsync();
        x.ShowAsync();
    }

When I run this application is OK until I click on the button and it's crash anyone know what is the problem with it

Upvotes: 1

Views: 2711

Answers (1)

Sunteen Wu
Sunteen Wu

Reputation: 10627

I can run it on local machine successfully but not in the real device (I use window phone and run on it)

You can connect to WCF service in your local PC machine, that's because your local WCF service application default hosed by IIS Express and have a default service address like http://localhost:.... So your client in local machine off course can invoke the WCF service deployed in local machine correctly by add the default address. But when you run your client on the real windows phone device,your WCF service doesn' deploy on your device , how your client connect to the WCF service by a localhost address?

If you want to invoke the WCF service correctly on your real device, you can publish the WCF service and set the right endpoint address of the client in the app and please make sure that your firewall does not block the service port

Upvotes: 1

Related Questions