Hi,
I am accessing my wcf service method which returns List<Term> by using service reference in project. But as per changes in requirement, I need to access it direct via URL. I tried to convert by facing some issue.
Following method is needed to convert into normal service. Please suggest.
public JsonResult GetAllPriprities()
{
try
{
//Creating object of MessageHeader class to pass MessageHeader with client request
MessageHeader header;
//Creating object of OperationContextScope class
OperationContextScope scope;
//Creating object of EmpServiceClient to access WCF service methods
SDServiceReference.Service1Client objSDServiceReference = new SDServiceReference.Service1Client();
//Validating the user by passing Username and Password
string requestedFromURL = System.Web.HttpContext.Current.Request.Url.AbsoluteUri;
if (Common.Sessions.isServiceAuthenticated == "" || Common.Sessions.isServiceAuthenticated == null)
{
userToken = objSDServiceReference.UserLogin(requestedFromURL);
if (userToken != "" && userToken != null)
{
Common.Sessions.isServiceAuthenticated = userToken;
//defining scope
scope = new OperationContextScope(objSDServiceReference.InnerChannel);
//Creating the Message header
header = MessageHeader.CreateHeader("TokenHeader", "TokenNameSpace", userToken);
//Adding the created Message header with client request
OperationContext.Current.OutgoingMessageHeaders.Add(header);
//Request1- Calling GetEmpData() method to get record
var lstPriorities = objSDServiceReference.getAllPriorities().ToList();
return Json(lstPriorities, JsonRequestBehavior.AllowGet);
}
else
{
return null;
}
}
else
{
userToken = Common.Sessions.isServiceAuthenticated;
Common.Sessions.isServiceAuthenticated = userToken;
//defining scope
scope = new OperationContextScope(objSDServiceReference.InnerChannel);
//Creating the Message header
header = MessageHeader.CreateHeader("TokenHeader", "TokenNameSpace", userToken);
//Adding the created Message header with client request
OperationContext.Current.OutgoingMessageHeaders.Add(header);
//Request1- Calling GetEmpData() method to get record
var lstPriorities = objSDServiceReference.getAllPriorities().ToList();
return Json(lstPriorities, JsonRequestBehavior.AllowGet);
}
}
catch (Exception ex)
{
return null;
}
}