c# - WCF. Set user credentials -
sorry, english bad.
i have wcf services project , asp.net mvc project i'm using ninject wcf client extension inject services in example
bind<iservice>().toservicechannel();
now i'm need add authentication , authorization wcf services. have implemented usernamepasswordvalidator
, iauthorizationpolicy
.
in examples used service reference , user credentials added here:
serviceclient host = new serviceclient(); host.clientcredentials.username.username = "user"; host.clientcredentials.username.password = "pass";
but didn't create service reference. have interfaces. , use here:
public class homecontroller : controller { private readonly iservice _service; public homecontroller(iservice service) { _service = service; } }
how can add user credentials?
you need create channelfactory set user credentials:
example :
var result = new channelfactory<iservice>("*", new endpointaddress(serviceaddress)); result.credentials.username.username = "username"; result.credentials.username.password = "password";
Comments
Post a Comment