我正在尝试从我的 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/