0

Sorry, my english is bad.

I have wcf services project and asp.net mvc project I'm using ninject wcf client extension to inject services like in this example

 Bind<IService>().ToServiceChannel();

Now i'm I need to add authentication and authorization for wcf services. I have implemented UserNamePasswordValidator and IAuthorizationPolicy.

In all examples used service reference and user credentials added like here:

ServiceClient host = new ServiceClient();
host.ClientCredentials.UserName.UserName = "user";
host.ClientCredentials.UserName.Password = "pass";

But i didn't create service reference. I have only interfaces. And use it like here:

public class HomeController : Controller
{
    private readonly IService _service;
    public HomeController(IService service)
    {
        _service = service;    
    }
}

How I can add user credentials?

1 Answers1

0

You need to create a channelFactory for you to set the user credentials:

Example :

var result = new ChannelFactory<IService>("*", new EndpointAddress(serviceAddress));
    result.Credentials.UserName.UserName = "Username";
    result.Credentials.UserName.Password = "password";
jtabuloc
  • 2,479
  • 2
  • 17
  • 33