这是我试图让这件事发挥作用的最后一站。
我在.net / C#中创建了一个WCF服务,它在亚马逊EC2实例的IIS(端口80)中托管。该服务使用OAuth2(GoogleWebAuthorizationBroker.AuthorizeAsync)授权服务读取/写入google驱动器的文件。客户端应用程序使用POST消息来调用触发auth的服务添加方法,然后将文件添加到google驱动器。
我的问题,我不遗余力,是当我在我的开发机器上运行服务时,(visual studio创建了IIS express实例),当发送POST时,客户端没有问题正确的成功响应并将文件添加到Google云端硬盘(该文件会传输到谷歌硬盘)。但是,当我将服务上传到我的Amazon EC2实例上的IIS并将客户端上的连接字符串更改为指向ec2实例时,该服务会从服务返回(400)错误请求。
我知道该服务适用于除谷歌授权和谷歌驱动器文件上传之外的所有内容,因为我删除了这个并且POST工作,但是当保留谷歌身份验证和谷歌驱动器文件上传时,我收到400错误请求..
在google开发者控制台中,我将uri的重定向设置为:
http://localhost:3537
http://localhost/authorize/
http://localhost:80/authorize/
http://localhost:80/TimesheetService.svc/authorize/
http://localhost/TimesheetService.svc/authorize/
http://localhost/authorize/

C#使用命名空间:
using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v2;
using Google.Apis.Drive.v2.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;

EC2 IIS设置: WCF服务作为新站点托管在IIS中,并指向localhost端口80
以下是在EC2上失败但未启用的OAuth代码:
private static String ACTIVITY_ID = "REMOVED";
static String CLIENT_ID = "REMOVED";
static String CLIENT_SECRET = "REMOVED";
static String APP_USER_AGENT = "ApplicationB";
static String[] SCOPES = new [] { DriveService.Scope.Drive };
/// <summary> Returns the request initializer required for authorized requests. </summary>
private static async Task<DriveService> GetCredentials()
{
ClientSecrets secrets = new ClientSecrets
{
ClientId = CLIENT_ID,
ClientSecret = CLIENT_SECRET
};
IDataStore credentialPersistanceStore = getPersistentCredentialStore();
UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(secrets,
SCOPES, getUserId(), CancellationToken.None, credentialPersistanceStore);
var service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = APP_USER_AGENT
});
return service;
}
/// <summary>
/// Returns an ID string for the current user. IDs are unique within this application.
/// </summary>
private static String getUserId()
{
// TODO: Generate a unique user ID within your system for this user. The credential
// data store will use this as a key to look up saved credentials.
return "MyGoogleEmail@Gmail.com";
}
/// <summary> Returns a persistent data store for user's credentials. </summary>
private static IDataStore getPersistentCredentialStore()
{
// TODO: This uses a local file store to cache credentials. You should replace this with
// the appropriate IDataStore for your application.
return new FileDataStore("Drive.Sample.Credentals");
}
&#13;
有人可以使用google OAuth了解我在EC2上使用IIS上的旋转WCF所面临的问题。我似乎无法让这个工作。