Mac

Mac

  • 1.1k
  • 286
  • 70.6k

Forms authentication with WCF service and asp.net in two virtual directory in same port

Dec 10 2010 1:34 AM

Hi guys,
I have one asp.net(c#) application and a asp.net enabled wcf service hosted in same port as two virtual directories. i have configured form authentication for both asp.net and asp.net enabled wcf service. When i am calling method in WCF Service from asp.net without forms authentication everything working fine. when i enable the forms authentication in wcf service . i get the following error with the contents of login page due to the unauthenticated service call.
i have pasted the some part of response below

"The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were"

   
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>


i have tried the solution i get from net by adding current authentication cookie using following code but i get the same issue.

   
 HttpRequestMessageProperty httpRequestProperty = new HttpRequestMessageProperty();
httpRequestProperty.Headers.Add(HttpRequestHeader.Cookie, FormsAuthentication.GetAuthCookie(User.Identity.Name, false).Value);
ServiceReference1.Service1Client serviceClient = new ServiceReference1.Service1Client();
using (OperationContextScope scope = new OperationContextScope(serviceClient.InnerChannel))
{
OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpRequestProperty;
string s = serviceClient.GetData(2);
}

I look forward for your reply. Tired of searching for the solution...

thanks in advance.