想要连接 Withings API。我在另一个项目中使用了相同的控制器,他在那里工作得很好。在站点是 Azure webrole 的项目中(不知道这是怎么回事),它不起作用。首先我得到了
“DotNetOpenAuth.Reporting”的类型初始值设定项引发异常。
所以我在 web.config 中将其关闭
报告已启用=“假”
现在我得到了
“DotNetOpenAuth.Logger”的类型初始值设定项引发异常。
我不使用 log4net。
public ActionResult StartOAuth()
{
var serviceProvider = GetServiceDescription();
var consumer = new WebConsumer(serviceProvider, _tokenManager);
// Url to redirect to
var authUrl = new Uri(Request.Url.Scheme + "://" + Request.Url.Authority + "/Withings/OAuthCallBack");
// request access
consumer.Channel.Send(consumer.PrepareRequestUserAuthorization(authUrl, null, null));
// This will not get hit!
return null;
}
private ServiceProviderDescription GetServiceDescription()
{
return new ServiceProviderDescription
{
AccessTokenEndpoint = new MessageReceivingEndpoint("https://oauth.withings.com/account/access_token", HttpDeliveryMethods.PostRequest),
RequestTokenEndpoint = new MessageReceivingEndpoint("https://oauth.withings.com/account/request_token", HttpDeliveryMethods.PostRequest),
UserAuthorizationEndpoint = new MessageReceivingEndpoint("https://oauth.withings.com/account/authorize", HttpDeliveryMethods.PostRequest),
TamperProtectionElements = new ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement() },
ProtocolVersion = ProtocolVersion.V10a
};
}
事实证明这是Azure的错。在web.config
有一个部分坏了DotnetOpenAuth。删除此部分是一种解决方法。可能会添加log4net也可以解决这个问题,但我没有测试。
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)