Skip to content

Adding Authentication

Cussa Mitre edited this page Feb 7, 2018 · 1 revision

When we are talking about Web Services, is totally normal that the owner of it will try to protect it against unauthorized access. And this is normally done by using authentication.

To make it easier, XitSoap already implements the two most used types of Authentication: BasicAuthentication and Bearer Token.

Adding a Basic Authentication

using HodStudio.XitSoap.Authentication;
...
var wsCon = new WebService("http://localhost/XitSoap/ProductService.asmx");
wsCon.SetAuthentication(new BasicAuthentication("user", "password"));
var result = wsCon.Invoke<Product>("SearchProduct");

Adding a Bearer Token Authentication

using HodStudio.XitSoap.Authentication;
...
var wsCon = new WebService("http://localhost/XitSoap/ProductService.asmx");
wsCon.SetAuthentication(new BearerTokenAuthentication("myBearerToken"));
var result = wsCon.Invoke<Product>("SearchProduct");