在服务/守护程序应用程序中使用MIP SDK保护文件时出错

时间:2019-07-18 15:38:01

标签: azure-information-protection microsoft-information-protection

有人可以帮助我解决以下问题吗?

场景。我在Azure VM上运行Windows服务。 Service接收文件,以某种方式修改它们(假设它向Word文件添加了自定义属性),并使用MIP SDK通过模板ID保护它们。

问题IFileHandler.SetProtection(string)+CommitAsync(...)失败,但出现以下异常:

发生一个或多个错误。 ServiceDiscoveryHelper :: GetServiceDetails-无法计算域:许可证域,身份和云端点基础URL都为空,correlationId:[9add32ba-0cb7-4d31-b9d8-0000b7c694a4]

其他信息

主代码段

MIP.Initialize(MipComponent.File);

var appInfo = new ApplicationInfo{
    ApplicationId = ConfigurationManager.AppSettings["AppPrincipalId"],
    ApplicationName = "App name",
    ApplicationVersion = "1.0.0",
};

var authDelegate = new AuthDelegateImplementation(appInfo);
var fileProfileSettings = new FileProfileSettings("mip_data", false,
    authDelegate, new ConsentDelegateImplementation(), appInfo, LogLevel.Trace);

var fileProfile = MIP.LoadFileProfileAsync(fileProfileSettings).Result;
var engineSettings = new FileEngineSettings("engine-id", "", "en-US"){
    Identity = new Identity($"{appInfo.ApplicationId}@<TENANT-NAME>"){
        DelegatedEmail = "<OWNER>@<TENANT-NAME>",
    },
};
var fileEngine = fileProfile.AddEngineAsync(engineSettings).Result;
var fileHandler = fileEngine.CreateFileHandlerAsync("c:\\sample.docx", "0", true).Result;
fileHandler.SetProtection(new ProtectionDescriptor("<TEMPLATE-ID>"));
var success = fileHandler.CommitAsync("c:\\encrypted.docx").Result;

AuthDelegateImplementation

public string AcquireToken(Identity identity, string authority, string resource)
    var authContext = new AuthenticationContext(authority + "/" + "<TENANT_ID>");
    var clientCredential = new ClientCredential("<CLENT_ID>", "<CLIENT_SECRET>");
    var res = await authContext.AcquireTokenAsync(resource, clientCredential);
    return res.AccessToken;
}

ConsentDelegateImplementation

public class ConsentDelegateImplementation : IConsentDelegate {
    public Consent GetUserConsent(string url) {
        return Consent.Accept;
    }
}

1 个答案:

答案 0 :(得分:0)

它表明在测试MIP的本地持久状态后(请参见UseInMemoryStorage处于无效状态时,请参见FileProfileSettings.Path属性)已损坏。删除“ mip_data”文件夹后,问题消失了。