2017-01-30 92 views
1

我試圖在.NET Core中執行SSRS報告。在.NET Core中對ReportExecution2005.asmx進行身份驗證

由於.NET Core不允許添加服務引用,因此您必須使用WCF連接服務來添加對WSDL的引用,以便它可以生成與.NET Core兼容的代碼。這是我爲ReportExecution2005.asmx做的(如果它很重要的話,SQL Server 2016)。

我試着用下面來對服務進行身份驗證:

var rsExec = new ReportExecutionServiceSoapClient(ReportExecutionServiceSoapClient.EndpointConfiguration.ReportExecutionServiceSoap, 
                new EndpointAddress("http://server/ReportServer/ReportExecution2005.asmx")) 
        { 
         ClientCredentials = 
         { 
          Windows = 
          { 
           AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation, 
           ClientCredential = new NetworkCredential("username", "password") 
          } 
         } 
        }; 

還試圖設置用戶名對象而不是Windows對象,但無論哪種方式,其結果是出現以下錯誤:

MessageSecurityException: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM'.

看着Fiddler,代碼不會傳遞證書。

這是得到了產生斷WSDL

public ReportExecutionServiceSoapClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) 
    : base(ReportExecutionServiceSoapClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress) 
{ 
    this.Endpoint.Name = endpointConfiguration.ToString(); 
    ConfigureEndpoint(this.Endpoint, this.ClientCredentials); 
} 

static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials); 

我可能是錯的,但不是這個調用私有方法ConfigureEndpoint與對象,甚至被設置ClientCredentials前ClientCredentials對象的代碼?

我沒有看到任何其他配置ClientCredentials或調用ConfigureEndpoint的方式,那麼您應該如何進行身份驗證?其他的構造函數基本上是一樣的,除了一個接受Binding而不是EndpointConfiguration的構造函數。有任何想法嗎?

+0

另外,我知道我可以把這個變成一個.net庫中,並從那裏引用它,但我想嘗試和只需使用.NET Core即可使用它。 – Brandon

+0

您的安全模型是如何設置的?您是否在ssrs實例上使用本地用戶從ssrs請求?如果是,該用戶是否有權這樣做? –

+0

另一件事是檢查你的wfc綁定的傳輸安全配置。 –

回答

0

編輯:更新的代碼.NET核心

不幸的是,我沒有SSRS這裏現在來測試代碼。

不過,試試這個代碼(沒有錯誤檢查):

// parameters of report (if any) 
ParameterValue[] parameters = {new ParameterValue {Name = "ApontamentoID", Value = "364"}}; 

// connect to the service 
ReportExecutionServiceSoapClient webServiceProxy = 
    new ReportExecutionServiceSoapClient(
    ReportExecutionServiceSoapClient.EndpointConfiguration.ReportExecutionServiceSoap, 
    "http://report_server_url/ReportExecution2005.asmx?wsdl"); 

// logon the user 
await webServiceProxy.LogonUserAsync("username", "password", null); 

// ask for the report 
await webServiceProxy.LoadReportAsync("/report_path", null); 
await webServiceProxy.SetExecutionParametersAsync(parameters, null); 

// you can use RenderStreamRequest too 
RenderRequest request = new RenderRequest("pdf", null); 
RenderResponse response = await webServiceProxy.RenderAsync(request); 

// save to the disk 
System.IO.File.WriteAllBytes(@"c:\temp\output.pdf", response.Result); 

// logoff the user 
await webServiceProxy.LogoffAsync(); 

// close 
await webServiceProxy.CloseAsync(); 
+0

這是.NET的核心代碼?我無法將ReportExecutionserviceSoapClient放入使用語句中,因爲它沒有實現IDisposable。 – Brandon

+0

ops。抱歉!現在我讀到你正在使用.net核心!我的錯!我正在使用NET 4.6.1。 –

+0

我更新了代碼!你可以檢查一下嗎?也許缺少一些東西,但我沒有找到任何示例或更好的文檔(就像關於ssrs的一切)。 –

相關問題