简体   繁体   中英

jQuery AJAX call to WCF service with custom principal

I have successfully created a WCF service using the webHttpBinding with no authentication or security. I can call my function over and over and it returns the value as expected.

Now I created a custom IAuthorizationPolicy, UserNamePasswordValidator and IPrincipal. I went back to wsHttpBinding (default) and did a normal service reference in code and set the ClientCredentials.UserName.UserName and ClientCredentials.UserName.Password appropriately and the service works perfectly fine. I modified the Username to be wrong just to ensure the code was firing and sure enough it failed.

So, I put the binding back to webHttpBinding, but now I cannot figure out how to set those credentials via jQuery. I have tried setting the "Authorization" header to a base64 encoded string using the following How can I pass windows authentication to webservice using jQuery? . No matter what i do i always get the error "No custom principal is specified in the authorization context".

Anyone have info on how to properly call a WCF REST service that is using a Custom Principal?

I was tryng to do something that is not possible. I have to use the standard HTTP Authentication method because I am working with a REST webservice and not a wsHttpBinding webservice which has alot more wrapped around it. I found my answer here:

http://www.leastprivilege.com/FinallyUsernamesOverTransportAuthenticationInWCF.aspx

var html = $.ajax({
  url: "some.jsp",
  username: "sdsdsdsdsd",
  passsword: "xxxxxxxx"
 }).responseText;

have tried just passing in the username and password

http://api.jquery.com/jQuery.ajax/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM