User/Pass Authentication using RESTful WCF & Windows Forms

前端 未结 4 1937
没有蜡笔的小新
没有蜡笔的小新 2020-12-12 13:44

What is the best approach to implementing authorisation/authentication for a Windows Forms app talking to an IIS-hosted RESTful WCF Service?

The reason I ask is I am

4条回答
  •  Happy的楠姐
    2020-12-12 14:06

    Using Basic authentication:

    WebHttpBinding binding = new WebHttpBinding();
    binding.SendTimeout = TimeSpan.FromSeconds(25);
    binding.Security.Mode = WebHttpSecurityMode.TransportCredentialOnly;
    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
    
    Uri address = new Uri("http://localhost:3525/WcfRestWeb/Quotes.svc");
    
    WebChannelFactory factory =
                 new WebChannelFactory(binding, address);
    
    factory.Credentials.UserName.UserName = "tan";
    factory.Credentials.UserName.Password = "wani";
    
    IQuoteService proxy = factory.CreateChannel();
    
    var response = proxy.GenerateQuote(GetQuoteRequest());
    Console.WriteLine("Quote Amount: " + response.QuoteAmount);
    

提交回复
热议问题