私はこの1つで私の頭を裂いている、私はブラウザを介して呼び出すことができますWCFサービスがあり、以下のメソッドは私が(401)無許可エラーを取得します。そして、サービスは呼び出されません。さらに、私のローカルマシン(IIS Expressを使用したデバッグモード)からWebアプリケーションを実行すると、私の開発サーバー(IIS7)が動作しますが、Webアプリケーションを開発サーバーにデプロイし、 401エラーに失敗します。私はこれがIIS7と関係があると思っていますが、私は100%確実ではないし、役立つことは非常に役に立つでしょう。WCFサービスに資格情報を渡していない401
私は答えをオンラインで見たことがありますが、私が見つけた最高のものはthisです。次のように
マイサービスコールは、次のとおりです。
var request = (HttpWebRequest) WebRequest.Create(url);
request.Method = "GET";
request.ContentType = "application/json; charset=utf-8";
request.AuthenticationLevel = AuthenticationLevel.MutualAuthRequested;
request.Credentials = CredentialCache.DefaultCredentials;
WebResponse responce = request.GetResponse();
Stream reader = responce.GetResponseStream();
var sReader = new StreamReader(reader);
string outResult = sReader.ReadToEnd();
sReader.Close();
var result = (T) JsonConvert.DeserializeObject(outResult, typeof (T));
return result;
サービスのための私の構成は次のようになります。直前に、私はクライアントサービスの呼び出しで、いくつかのログを入れている
<service name="RGMPServices.Householding.Services.AccountService" behaviorConfiguration="Default">
<endpoint address="" kind="webHttpEndpoint" endpointConfiguration="SecuredHttpEndpointBinding" contract="RGMPServices.Householding.Contracts.IAccountService" />
</service>
<service name="RGMPServices.Householding.Services.HouseholdService" behaviorConfiguration="Default">
<endpoint address="" kind="webHttpEndpoint" endpointConfiguration="SecuredHttpEndpointBinding" contract="RGMPServices.Householding.Contracts.IHouseholdService" />
</service>
<service name="RGMPServices.Householding.Services.UserService" behaviorConfiguration="Default">
<endpoint address="" kind="webHttpEndpoint" endpointConfiguration="SecuredHttpEndpointBinding" contract="RGMPServices.Householding.Contracts.IUserService" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehaviour">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint name="SecuredHttpEndpointBinding" helpEnabled="true" automaticFormatSelectionEnabled="true">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</standardEndpoint>
</webHttpEndpoint>
</standardEndpoints>
私はサービスを呼び出し、応答は:
DEBUG 2013-10-01 13:15:13,569 452ms ServiceGetSingle - Passing Login: MYLANDOMAIN\MYLANUSERNAME
ERROR 2013-10-01 13:15:13,631 514ms ServiceGetSingle - ERROR Calling ServiceGetSingle with user credentials login: MYLANDOMAIN\MYLANUSERNAME System.Net.WebException: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() at Householding.Common.ServiceHelper.ServiceGetSingle[T](String url)
コードは次のようになります。
私はまだ再びWCFサービスにアクセスするために私を許可していないが、私のドメインアカウントに私のウェブサイトのためのアプリケーションプールを設定してもlogger.Debug("Passing Login: "
+ System.Security.Principal.WindowsIdentity.GetCurrent().Name)
:それはブラウザのために働いています。とても奇妙!
WCFとWindows認証が動作するのは必ずしも容易ではありません。 httpフローをトレースするには、クライアントでFiddlerを試してみてください。また、サーバー上でWCFトレースを構成してみてください。http://msdn.microsoft.com/en-us/library/ms733025.aspx – Joe