2012-03-30 14 views
5

私はそれを展開しているサーバー(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に精通しているわけではありませんが、これは問題の原因を示唆している可能性があります。要求のルーティングに関連するものかもしれません。

私はアイデアが不足しているので、私はここに誰かが問題が何であるかを認識することを望んでこれを掲示しています。どんな提案も大歓迎です。

+1

IISでURL書き換えを有効にしていますか?これは何らかの権限の問題のようなにおいがします。 [IIS7のクラシックと統合パイプラインモードの違いは何ですか?](http://stackoverflow.com/questions/3062709/what-is-the-difference-between-classic-and-integrated-pipeline-mode-in- iis7)役に立つかもしれない。 –

+0

@PetarVucetinサーバーでURLの書き換えが有効になっていないことを確認しました。あなたのコメントは私の質問に正確には答えられませんでしたが、あなたが提供したリンクは私にいくつかのアイデアを与えました - 問題が現れない統合されたパイプラインモードで動作するようにアプリケーションを再構成することができました。私はまだ古典的なパイプラインモードで動作させる方法を知りたいですが、もし私が私のためにあなたのコメントが賞金のための最善の候補者であることを明確にする良い答えが得られなければ。結局のところ、すぐに問題を解決することができました。 –

+0

Damirに感謝します。私はしばらくすると、問題を再現しようとすることができます。それはちょうど私のデバッグボーンをくすぐる... –

答えて

0

アドレスは「〜/ Service1.svc」である場合には問題が

アドレス「〜/ Service1.svc /問題」であってもよい通話がSVCファイルをヒットし、見つけるために、ファイル内の情報を使用していますそのインタフェースの設定を行います。

svcファイルなしで相対アドレスを使用すると、configファイル内のアドレスが参照されます。

いずれかのサーバーに「Service1.svc」というディレクトリがありますか、またはサーバー上に「.svc」がないアドレスですか?

+0

どちらもありません。テスト目的のトラブルシューティングの際には、上記のテストプロジェクトのファイル( 'Service1.svc'、' Web.config'、 'bin \ TestService.dll')だけですべてのサーバー上に新しいアプリケーションを作成しました。 –

1

IISでURL書き換えを有効にしていますか?これは何らかの権限の問題のようなにおいがします。 What is the difference between Classic and Integrated pipeline mode in IIS7?役に立つかもしれません。

+0

リンクをありがとう。それは私に違いについて読んで、私は最終的に私のアプリを統合パイプラインモードで動作させることができました。私はまだそれが古典的なパイプラインモードではそのサーバー上で動作しない理由は、まだ興味があります。 –

関連する問題