我开发了一个用于定时上传Youtube的小C#应用程序。我有一个UI应用程序,它应该通过WCF与后台服务进行通信。这个后台服务可以完成与Youtube相关的所有工作。
我实现了后台服务作为windows服务,工作正常。
但是,如果windows服务试图获取凭据,我就会遇到WCF- timeout。就我调试问题而言,在调用以下命令之后:
using(var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
{
_credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[]{YouTubeService.Scope.Youtube, YouTubeService.Scope.YoutubeUpload},
"user",
CancellationToken.None);
}什么都没发生。通常会出现一个浏览器窗口,为应用程序提供访问权限(如果我在普通应用程序中执行相同的操作,它会这样做)。
这与windows-service的访问级别有关吗?我用过ServiceAccount.LocalSystem。
如果我在一个普通的控制台应用程序中实现它,那么整个WCF和youtube代码都可以正常工作,但是在windows服务中它会超时。
发布于 2016-03-12 03:25:42
试试这个:
var _credential = await
GoogleWebAuthorizationBroker.AuthorizeAsync(UriFromRelativePath(this, "/API/client_secret.json"), new[] { YouTubeService.Scope.Youtube, YouTubeService.Scope.YoutubeUpload },
"user",
CancellationToken.None);
public static Uri UriFromRelativePath(FrameworkElement parent, string path)
{
try
{
var uri = new Uri(parent.BaseUri, path);
return uri;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}https://stackoverflow.com/questions/35939550
复制相似问题