如何将当前安全上下文传递给Web请求? [英] How to pass current security context to web request ?

查看:85
本文介绍了如何将当前安全上下文传递给Web请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个作为Windows服务运行的WCF服务。它与特定用户一起作为安全上下文(username@domain.com)运行。其中有一个方法调用REST API Web服务。我想将WCF服务的凭据传递给REST请求。我试过下面的代码,但它不起作用。我得到的只是来自REST Web服务的Unauthorized(401)错误。

I have a WCF service running as a windows service. It is running with a specific user as a security context (username@domain.com) . There is a method in it which calls a REST API web service. I wanted to pass credentials of WCF service to REST request. I tried below code but it is not working. All I am getting is Unauthorized (401) error from REST web service.

Uri uri = new Uri(objM3API.URL);
ICredentials credentials = CredentialCache.DefaultCredentials;
NetworkCredential credential = credentials.GetCredential(uri, "Basic");

request.Credentials = credential;
request.Accept = "application/json";
// Get response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
    if (response.StatusCode == HttpStatusCode.OK)
    {







到目前为止,我尝试在将NetworkCredential对象创建为Negotiate和NTLM时更改身份验证类型,但这也无效。我不想创建传递用户名和密码的NetworkCredential对象(请求公司使用服务的安全上下文而不是直接传递值)。



我们将非常感谢任何帮助




So far I tried changing Authentication type when creating NetworkCredential object to "Negotiate" and "NTLM" but that did not work either. I don't want to create NetworkCredential object passing user name and password ( Request from company to use security context of the service rather than passing value directly ) .

Any help will be greatly appreciated

推荐答案

这篇关于如何将当前安全上下文传递给Web请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆