2017-01-30 10 views
1

.NETコアでSSRSレポートを実行しようとしています。.NETコアでReportExecution2005.asmxを認証する

.NET Frameworkではサービス参照を追加できないため、WCF Connected Serviceを使用して.NET Core互換コードを生成できるようにWSDLへの参照を追加する必要があります。これは、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を見ると、コードは資格情報を渡していません。

これは私が誤解されるかもしれないが、このClientCredentialsオブジェクトも設定されていた前のオブジェクトClientCredentialsプライベートメソッドConfigureEndpointを呼び出していません?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); 

オフ生成されてしまったコードですか

ClientCredentialsを設定したり、ConfigureEndpointを呼び出す方法が他にないので、どのように認証する必要がありますか?他のコンストラクタは、基本的には同じですが、EndpointConfigurationの代わりにBindingをとるコンストラクタは例外です。何か案は?

+0

はまた、私はちょうど、.NET Frameworkライブラリにこれを入れて、そこからそれを参照することができます知っているが、私は試してみたいのですが.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 Coreコードですか? IDisposableを実装していないため、ReportExecutionserviceSoapClientをusingステートメントに入れることはできません。 – Brandon

+0

ops。ごめんなさい!今、私はあなたが.netコアを使っていることを読んでいます!私の悪い!私はNET 4.6.1を使用しています。 –

+0

コードを更新します。あなたは確認できますか?たぶん欠けているものがあるかもしれませんが、私はssrsに関するすべてのような例やより良い文書を見つけられませんでした。 –

関連する問題