We are using an ASP.NET web application that consumes WCF service.
From javascript we are calling AjaxWebService.svc service (AJAX enabled) in following way and from AjaxWebServcice.svc we will actually call WCF service.
// CRM.js
GetAjaxService().GetUsers(function (result) {
if (result != null) {
// Process result
}
});
// Infrastructure.js
function GetAjaxService() {
if (ajaxWebService == null) {
ajaxWebService = new AjaxWebService();
}
if (ajaxWebService == null) {
alert('ajax service failed!!');
}
return ajaxWebService;
}
AjaxWebService.svs.cs:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]
[ServiceContract(Namespace = "", SessionMode = SessionMode.Allowed)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class AjaxWebService
{
[OperationContract]
public UsersData[] GetUsers()
{
this.Service.GetUsers(); --> calls WCF service API
}
}
The service works fine when I call it directly, but I need to know how we can pass custom headers (e.g., the user-agent header) when using the GetAjaxService()
approach.
The WCF service call works fine, but we are facing a problem. When we use fetch()
or XMLHttpRequest()
, I can easily pass headers (such as the User-Agent
header). However, with the current GetAjaxService().GetUsers()
approach, we need to know how to pass custom headers.
Any help or guidance on how to modify the GetAjaxService()
call to include headers would be appreciated.