私はそれを展開しているサーバー(Windows Server 2008 R2マシン)にWindows認証を使用しているWCFサービスに問題があります。私がアクセスできる他のマシン(Windows 7、Windows Server 2008、Windows Server 2008 R2)にも完璧に対応しています。問題の原因として私のコードを多かれ少なかれ完全に除外した、本当に簡単なサンプルアプリケーションで問題を再現することができました。Windows認証でWCFサービスを呼び出すときにURLを実行できませんでした
私は問題を再現できる最小のアプリケーションは、WCFサービスのプロジェクトテンプレートのマイナーな修正である:
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetData(int value);
}
[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}\nUsername: {1}",
value,
ServiceSecurityContext.Current == null ?
"<null>" :
ServiceSecurityContext.Current.PrimaryIdentity.Name);
}
}
実際のコードは、のためのHttpHandlerを使用しているため、基本的に私は(私はそれを必要とASP.NETとの互換性を有効に認証されたユーザのユーザ名が返されます。
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Windows"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="HttpWindowsBinding" maxReceivedMessageSize="2147483647">
<readerQuotas maxBytesPerRead="2147483647" maxArrayLength="2147483647" maxStringContentLength="2147483647" maxNameTableCharCount="2147483647" maxDepth="2147483647"/>
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
<services>
<service name="TestService.Service1" behaviorConfiguration="ServiceBehavior">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="HttpWindowsBinding"
contract="TestService.IService1" />
<endpoint address="problem"
binding="basicHttpBinding"
bindingConfiguration="HttpWindowsBinding"
contract="TestService.IService1" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
注意2つのエンドポイント:デフォルトアドレスを有するもの、相対アドレスを持つ他方次のようにweb.config
の
内容です。最初のものを呼び出すと、二番目の呼び出しが次のエラーで失敗しながら、でも問題のあるサーバー上で成功した:
はException type: HttpException
Exception message: Failed to Execute URL.
at System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6.BeginExecuteUrl(String url, String method, String childHeaders, Boolean sendHeaders, Boolean addUserIndo, IntPtr token, String name, String authType, Byte[] entity, AsyncCallback cb, Object state)
at System.Web.HttpResponse.BeginExecuteUrlForEntireResponse(String pathOverride, NameValueCollection requestHeaders, AsyncCallback cb, Object state)
at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
は、古典的なパイプラインが使用される場合にのみに障害が発生したコールは、(私が原因のHttpHandlerのそれを必要と
が、それをなくしても問題を再現することができます)。統合されたパイプラインでは、問題はなくなりました。私はWindows認証を無効にした場合も、問題は同様に行っている:
<binding name="HttpBinding" maxReceivedMessageSize="2147483647">
<readerQuotas maxBytesPerRead="2147483647" maxArrayLength="2147483647" maxStringContentLength="2147483647" maxNameTableCharCount="2147483647" maxDepth="2147483647"/>
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
私は登録のHttpHandlerで別の詳細に気づきました。相対アドレスを持つエンドポイントのHttpRequest.CurrentExecutionFilePathプロパティの値は、問題のあるサーバー(~/Service1.svc/problem
)と作業サーバー(~/Service1.svc
)の間で異なります。 IISに精通しているわけではありませんが、これは問題の原因を示唆している可能性があります。要求のルーティングに関連するものかもしれません。
私はアイデアが不足しているので、私はここに誰かが問題が何であるかを認識することを望んでこれを掲示しています。どんな提案も大歓迎です。
IISでURL書き換えを有効にしていますか?これは何らかの権限の問題のようなにおいがします。 [IIS7のクラシックと統合パイプラインモードの違いは何ですか?](http://stackoverflow.com/questions/3062709/what-is-the-difference-between-classic-and-integrated-pipeline-mode-in- iis7)役に立つかもしれない。 –
@PetarVucetinサーバーでURLの書き換えが有効になっていないことを確認しました。あなたのコメントは私の質問に正確には答えられませんでしたが、あなたが提供したリンクは私にいくつかのアイデアを与えました - 問題が現れない統合されたパイプラインモードで動作するようにアプリケーションを再構成することができました。私はまだ古典的なパイプラインモードで動作させる方法を知りたいですが、もし私が私のためにあなたのコメントが賞金のための最善の候補者であることを明確にする良い答えが得られなければ。結局のところ、すぐに問題を解決することができました。 –
Damirに感謝します。私はしばらくすると、問題を再現しようとすることができます。それはちょうど私のデバッグボーンをくすぐる... –