windows - 如何将当前 Windows 凭据从使用 JS 制作的 Windows 8 native 应用程序传递到 WCF REST 服务?

标签 windows rest windows-8 wcf-rest windows-runtime

我正在尝试从我的 Windows 8 应用程序调用 WCF REST 服务,但系统始终提示我输入凭据。我在包 list 中激活了默认 Windows 凭据,正在寻找

的等价物
HttpClientHandler handler = new HttpClientHandler(); 
handler.UseDefaultCredentials = true;

使用 javascript 时。

该服务设置为使用 windows 身份验证,并且在从 IE9 调用时工作正常。

最佳答案

您可以使用 Winjs.xhr打电话。确保 defaultWindowsCredentials在 appxmanifest 中设置(如您所说)。

示例用法:

WinJS.xhr({
    url: requestUrl, user: 'username', pass: 'password, headers: { accept: 'application/json'}
}).then(
    function (req) {
    var data = JSON.parse(req.response);
    document.getElementById('foo').innerHTML = data.d[0].;
    // Now call the user-supplied callback function when this data is ready
    c({
       results: data.d,
        number: data.d.length
    });
},  //Error func
    function (req) {
    e(req);
}, //progress func
    function (req) {
    p(req);
}
);

您还可以使用 c# 项目来处理 WCF 通信并让 Javascript 项目调用它的方法。

其他认证路径:

Windows.Security.Authentication.Live “使 Metro 风格应用程序能够使用 Windows Live 来验证使用其 Windows Live ID 的用户”

另请查看 Metro style app for banking: code walkthrough具有多种身份验证方案和 Web Authentication .

Live SDK Developer Preview还将使您能够“在 Windows Developer Preview 中利用使用 Windows Live ID 的单点登录方案”。

关于windows - 如何将当前 Windows 凭据从使用 JS 制作的 Windows 8 native 应用程序传递到 WCF REST 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8939583/

相关文章:

rest - 在 ASP.Net Web API 中,如何伪造 PUT 和 DELETE?

javascript - 每次使用 Express 和 Node.js 的 RestFul API 都会崩溃,如何解决这个问题?

c# - Windows 8 Metro ListView - 无法禁用 ScrollViewer (C#/XAML)

.net - 使用 Inno Setup 在 Windows 8 上安装 .Net 3.5

linux - 在 Linux .NET Core 上生成类似 Windows 的友好时区名称列表

c++ - 从 C++ 程序激活 Windows 时出错

c++ - 如何正确终止 dll 中的挂起线程?

c# - 在 UWP 应用程序上滚动时禁用枢轴滑动

java - Gson Instance Creator 创建了实例,但字段为空

.net - Metro 应用程序 (.NET) 中的受控非 UI 计时器