-
Notifications
You must be signed in to change notification settings - Fork 75
ClientBaseExtensions
Rico Suter edited this page Jun 10, 2015
·
2 revisions
- Package: MyToolkit.Extended
- Platforms: WPF
This extension methods can be used to authenticate an ASP.NET authenticated WCF service. You need to create an AuthenticationService which has to be called first to authenticate and read the session cookie:
String cookies = null;
var auth = new AuthenticationServiceClient();
using (new OperationContextScope(auth.InnerChannel))
{
auth.Login("user", "password", null, true);
cookies = auth.GetIncomingCookies();
}
Then inject the cookie into your service or your HTTP call:
In a WCF service client:
var svc = new DataServiceClient();
using (new OperationContextScope(svc.InnerChannel))
{
svc.SetOutgoingCookies(cookies);
svc.GetData(...);
}
In a DataServiceContext:
var client = new DataServiceClient();
client.SendingRequest += ClientBaseExtensions.SendingRequest(cookies);
var person = client.Persons.Single(p => p.Firstname == "Test");