📜 ⬆️ ⬇️

Work with SOAP service from Windows Phone 8.1 applications

With the release of Windows Phone 8.1, a new feature has emerged in developing applications for the Windows / Windows phone store with a common code base. These are the so-called universal applications based on a more general API and the reusability of XAML markup in Visual Studio 2013 right out of the box.

If a Windows Store application uses WCF to work with SOAP services, then an attempt to port it to a Windows phone may fail. As it turned out, the System.ServiceModel namespace is no longer available. Accordingly, a replacement is required that meets the following requirements:


A SOAP request is a specially formed XML document. All you need to do is serialize the request data to XML, put it in the Body element and send it in the body of the HTTP POST request. The structure of the response is similar, the result is obtained from the Body element.


')
Based on the HttpClient, we implement the base class to form a request. As a result, we obtain a function of the following form:

public async Task<TResponse> CallAsync<TRequest, TResponse>(string action, TRequest request) { IHttpContent httpContent = GetHttpContent(action, request); var response = await Client.PostAsync(EndpointAddress, httpContent); var responseContent = await response.Content.ReadAsStringAsync(); return GetResponse<TResponse>(responseContent); } 


It remains only to substitute the corresponding classes TRequest and TResponse which can be obtained on the basis of the description of the service. SOAP services are described using Web Services Description Language ( WSDL ), a language that describes the service API in the form of operations and data types.

To obtain information about the service can be approached from different sides:



The source code obtained using SvcUtil cannot be directly used for Windows Phone store applications due to the presence of the following unsupported constructs:

Source: https://habr.com/ru/post/233799/


All Articles