Windows サービスから SQL Server Reporting Services の Web サービスを呼び出そうとしています。Asp.Net MVC Web サイトから正常に呼び出すことができますが、Windows サービスからまったく同じコードを使用しようとすると (一見同じ WCF 構成で)、次のエラーが発生します...
内部例外: System.ServiceModel.Security.MessageSecurityException - クライアント認証スキーム 'Ntlm' で HTTP 要求が承認されていません。サーバーから受信した認証ヘッダーは「NTLM」でした。
内部例外: System.Net.WebException - リモート サーバーがエラーを返しました: (401) 権限がありません。
Asp.Net MVC サイトのアプリケーション プールと Windows サービスの両方が、「ネットワーク サービス」ユーザーを使用するように設定されています。
これが構成ファイル内の私のWCF構成です...
<system.serviceModel>
<serviceHostingEnvironment
aspNetCompatibilityEnabled="true"/>
<bindings>
<basicHttpBinding>
<binding name="ReportExecutionServiceSoap" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxArrayLength="2147483647"
maxStringContentLength="2147483647"
maxBytesPerRead="2147483647"
maxDepth="2147483647"
maxNameTableCharCount="2147483647"
/>
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="None" realm=""/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://myserver/ReportServer_MSSQL2008/ReportExecution2005.asmx"
binding="basicHttpBinding" bindingConfiguration="ReportExecutionServiceSoap"
contract="ReportService.ReportExecutionServiceSoap" name="ReportExecutionServiceSoap" behaviorConfiguration="ImpersonationBehaviour" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="ImpersonationBehaviour">
<clientCredentials>
<windows allowedImpersonationLevel="None" allowNtlm="true"/>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
私はさまざまな「allowedImpersonationLevel」をすべて試しましたが、この動作をまったく定義せずに試しました。