Search code examples
wcfuwp

How to reference the WCF service by code-behind in UWP?


Now I need to reference a WCF service in a UWP program. However, the address of the WCF service may change frequently in the future.

I don't want to rebuild/republish the project every time when the address change.

So I want to use a LocalSettings to Save/Load the address of WCF service. Every the program begins, it will reload the address from the LocalSettings. And if the address changes, I just only let the customer change the LocalSettings from UI but not need to rebuild/republish the project.

How can I do it? Or there is any other better to do it?


Solution

  • If it's a RESTful service, you could use HttpClient relevant APIs to consume a REST service in UWP.

    Please note that REST is a resource that implements a uniform interface using standard HTTP GET, POST, PUT methods that can be located by URI. So, you could use HttpClient to call it in code-behind. You will get response after you send http request, then you could analysis the response result.

    The similar thread for your reference: Calling web service asynchronously in page constructor.