简体   繁体   English

使用自定义主体对WCF服务进行jQuery AJAX调用

[英]jQuery AJAX call to WCF service with custom principal

I have successfully created a WCF service using the webHttpBinding with no authentication or security. 我已经使用webHttpBinding成功创建了WCF服务,没有身份验证或安全性。 I can call my function over and over and it returns the value as expected. 我可以一遍又一遍地调用我的函数,它会按预期返回值。

Now I created a custom IAuthorizationPolicy, UserNamePasswordValidator and IPrincipal. 现在,我创建了一个自定义IAuthorizationPolicy,UserNamePasswordValidator和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. 我返回到wsHttpBinding(默认),并在代码中进行了常规服务引用,并适当地设置了ClientCredentials.UserName.UserName和ClientCredentials.UserName.Password,该服务运行良好。 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. 因此,我将绑定放回了webHttpBinding,但是现在我不知道如何通过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? 我尝试使用以下方法将“ Authorization”标头设置为base64编码的字符串如何使用jQuery将Windows身份验证传递给Web服务? . 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? 任何人都有有关如何正确调用使用自定义委托人的WCF REST服务的信息?

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. 我必须使用标准的HTTP身份验证方法,因为我使用的是REST网络服务,而不是wsHttpBinding网络服务,该服务周围有很多包装。 I found my answer here: 我在这里找到了答案:

http://www.leastprivilege.com/FinallyUsernamesOverTransportAuthenticationInWCF.aspx 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/ http://api.jquery.com/jQuery.ajax/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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