Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Windows 8 introduces a new type of application called Windows Store applications. These applications are designed around a touch screen interface. .NET Framework 4.5 enables Windows Store applications to call WCF services.
A subset of WCF functionality is available from within a Windows Store application, see the following sections for more details.
Important
Use the WinRT syndication APIs instead of those exposed by WCF. For more information see, WinRT Syndication API
Warning
Using Add Service Reference to add a web service reference to a Windows Runtime Component isn't supported.
The following WCF bindings are supported in Windows Store Applications:
The following binding elements are supported in Windows Store Applications
Both Text and Binary encodings are supported. All WCF transfer modes are supported. For more information see, Streaming Message Transfer.
To call a WCF service from a Windows Store application, use the Add Service Reference feature of Visual Studio 2012. You will notice a few changes in the functionality of Add Service Reference when done within a Windows Store application. First no configuration file is generated. Windows Store applications do not use configuration files, so they must be configured in code. This configuration code can be found in the References.cs file generated by Add Service Reference. To see this file, make sure to select "Show All Files" in the solution explorer. The file will be located under the Service References and then Reference.svcmap nodes within the project. All operations generated for WCF services within a Windows Store application will be asynchronous using the Task-based asynchronous pattern. For more information, see Async Tasks - Simplify Asynchronous Programming with Tasks.
Because configuration is now generated in code, any changes made in the Reference.cs file would be overwritten every time the service reference is updated. To remedy this situation the configuration code is generated within a partial method, which you can implement in your client proxy class. The partial method is declared as follows:
static partial void Configure(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint,
System.ServiceModel.Description.ClientCredentials clientCredentials);
You can then implement this partial method and change the binding or endpoint in your client proxy class as follows:
public partial class Service1Client : System.ServiceModel.ClientBase<MetroWcfClient.ServiceRefMultiEndpt.IService1>, MetroWcfClient.ServiceRefMultiEndpt.IService1
{
static partial void Configure(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint,
System.ServiceModel.Description.ClientCredentials clientCredentials)
{
if (serviceEndpoint.Name ==
ServiceRefMultiEndpt.Service1Client.EndpointConfiguration.BasicHttpBinding_IService1.ToString())
{
serviceEndpoint.Binding.SendTimeout = new System.TimeSpan(0, 1, 0);
}
else if (serviceEndpoint.Name ==
ServiceRefMultiEndpt.Service1Client.EndpointConfiguration.BasicHttpBinding_IService11.ToString())
{
serviceEndpoint.Binding.SendTimeout = new System.TimeSpan(0, 1, 0);
clientCredentials.UserName.UserName = "username1";
clientCredentials.UserName.Password = "password";
}
else if (serviceEndpoint.Name ==
ServiceRefMultiEndpt.Service1Client.EndpointConfiguration.NetTcpBinding_IService1.ToString())
{
serviceEndpoint.Binding.Name = "MyTcpBinding";
serviceEndpoint.Address = new System.ServiceModel.EndpointAddress("net.tcp://localhost/tcp");
}
}
}
The following serializers are supported in Windows Store applications:
DataContractSerializer
DataContractJsonSerializer
XmlSerializer
Warning
XmlDictionaryWriter.Write(DateTime) now writes the DateTime object as a string.
The following security modes are supported in Windows Store applications:
The following client credential types are supported in Windows Store applications:
None
Basic
Digest
Negotiate
NTLM
Windows
Username (Message Security)
Windows (Transport Security)
In order for Windows Store applications to access and send default Windows credentials, you must enable this functionality within the Package.appmanifest file. Open this file and select the Capabilities tab and select "Default Windows Credentials". This allows the application to connect to intranet resources that require domain credentials.
Important
In order for Windows Store applications to make cross machine calls you must enable another capability called "Home/Work Networking". This setting is also in the Package.appmanifest file under the Capabilities tab. Select the Home/Work Networking checkbox. This gives your application inbound and outbound access to the networks of the user's trusted places like home and work. Inbound critical ports are always blocked. For accessing services on the internet you must also enable Internet (Client) capability.
The use of the following classes is supported for Windows Store Applications:
We recommend only defining asynchronous service operations using the task-based async pattern. This ensures Windows Store applications remain responsive while calling a service operation.
Warning
While no exception will be thrown if you define a synchronous operation, it is strongly recommended to only define asynchronous operations.
As mentioned before all configuration must be done in code in the GetBindingForEndpoint method in the generated proxy class. Calling a service operation is done the same as calling any task-based asynchronous method as shown in the following code snippet.
void async SomeMethod()
{
ServiceClient proxy = new ServiceClient();
Task<T> results = await proxy.CallAsync(param1, param2);
T result = results.Result;
if (result.Success)
{
// Do something with result
}
}
Notice the use of the async keyword on the method making the asynchronous call and the await keyword when calling the asynchronous method.
Events
Mar 17, 9 PM - Mar 21, 10 AM
Join the meetup series to build scalable AI solutions based on real-world use cases with fellow developers and experts.
Register nowTraining
Module
Consume REST web services in .NET MAUI apps - Training
Consume a REST web service by using HttpClient and perform basic CRUD operations. You'll detect when your device is connected to the internet to provide a good user experience and take advantage of the native networking stacks to get top performance.
Documentation
How to: Programmatically Add Discoverability to a WCF Service and Client - WCF
Learn more about: How to: Programmatically Add Discoverability to a WCF Service and Client
Extending Hosting Using ServiceHostFactory - WCF
Learn more about: Extending Hosting Using ServiceHostFactory
How to: Configure WCF Service to Interoperate with ASP.NET Web Service Clients - WCF
Learn more about: How to: Configure WCF Service to Interoperate with ASP.NET Web Service Clients