2017-04-05 18 views
0

私は3日間厳しい問題に直面しています。 IIS 8.5にWCF Web API(.svcサービスファイル)を展開しました。アプリケーションが正常に動作していて、突然、コード内のその他のマイナーなものを変更した後、この問題が発生します。私は(localhostを使用して)サーバー内部からアプリケーションに接続できます。私は、サーバーのIPアドレスを使用して、外部から接続することができます。しかし、私は決してサーバーのホスト名を使用して外部から接続することはできません。この問題は、以下の例で最もよく理解できます。ホスト名を使用してWCFサービスにアクセスできない

注:このアプリケーションは、メインWebサイト内のIISアプリケーションです。作品:サービスのURIはhttp://myhostname/api/servicos.svc

私は多くのウェブサイトやフォーラムで検索しましたが、利用できません。

私のweb.configファイル:

'/アピ' でサーバーエラーが発生しました:私は(ホスト名を経由して)外部からAPIにアクセスしようとしたときに提示しています

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <appSettings> 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> 
    </appSettings> 

    <system.web> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5" /> 
    <customErrors mode="Off" /> 
    </system.web> 

    <connectionStrings> 
    <!-- My connection string goes here --> 
    </connectionStrings> 

    <system.serviceModel> 
    <services> 
     <service name="ServicoWeb.servico" behaviorConfiguration="Wcf_Behavior"> 
     <endpoint name="" binding="webHttpBinding" contract="ServicoWeb.IServico" /> 
     </service> 
    </services> 

    <behaviors> 
     <endpointBehaviors> 
     <behavior> 
      <webHttp automaticFormatSelectionEnabled="true" defaultBodyStyle="Bare" /> 
     </behavior> 
     </endpointBehaviors> 

     <serviceBehaviors> 
     <behavior name="Wcf_Behavior"> 
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 

    <protocolMapping> 
     <add binding="basicHttpsBinding" scheme="https" /> 
    </protocolMapping> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" /> 
    </system.serviceModel> 

    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <add name="removeSvcDaUrl" type="ServicoWeb.Validacao.UrlCustomizacao, ServicoWeb" /> 
    </modules>  
    <directoryBrowse enabled="true" /> 
     <rewrite>   
      <rules> 
       <remove name="WordPress: https://myhostname.com" /> 
      </rules> 
     </rewrite> 
     <handlers accessPolicy="Read, Execute, Script" /> 
     <security> 
      <requestFiltering> 
       <verbs> 
        <add verb="*" allowed="true" /> 
       </verbs> 
      </requestFiltering> 
     </security> 
    </system.webServer> 
</configuration> 

エラーがこれです応用。

リソースが見つかりません。

概要HTTP 404。探しているリソース(またはその 依存関係の1つ)が削除されたか、名前が変更されたか、または が一時的に利用できませんでした。次のURLを参照し、 のスペルが正しいことを確認してください。

要求されたURL:/Api/servico.svc/asos/csv/09655055000104

バージョン情報:Microsoft .NET Frameworkのバージョン:4.0.30319; ASP.NETバージョン:4.6.1069.1

このバグを修正するにはどうすればよいですか?

編集:もう1つの情報:IISの同じWebサイト内にある他のアプリケーションが動作します。 C#で書かれた他のWeb APIもあります。ここのように、これらはすべて正しく動作します。

編集2:もう一つ重要なことは、サービス自体(servico.svc)までサービスパスにアクセスできることです。たとえば、「http://myhostname.com/api/servico.svc?wsdl」にアクセスしようとすると、サービスのメタデータが正常に取得されます。したがって、サービス自体にアクセスしようとするときだけ、上記のエラーが発生します。

答えて

0

私はついにそれを解決しました!この問題に苦しんでいる人には、Amazon EC2ロードバランスが私のトラブルの原因でした。

ロードバランスがすべての要求をフィルタリングし、トランスポート層SSLセキュリティプロトコル(HTTPS)を使用してサーバーマシンに送信するように設定されていました。だから、私が要求するならば、http://myserver.com/servico Amazon Load Balanceは内部でhttps://machine-n/servicoにリダイレクトされます。ここで 'n'は使用されたマシンです(私の場合、2台のマシンがあります)。

私の問題は、WCF内で、これが原因でした。私のweb.configでは、サービスがHTTPS要求を受け入れることができませんでした。一度これを修正すると、すべて正常に機能しました。

HTTPを使用してマシンのIPアドレスを使用して直接要求したときにすべての機能が動作する理由についても説明します。この場合、負荷分散はHTTPSを使用して要求をフィルタリングしてリダイレクトしません。

ので、ここでは現在、HTTPSリクエストできるように、私のweb.configファイルを持っている:こんにちは

<?xml version="1.0" encoding="UTF-8"?> 
...  
<system.serviceModel> 
    <services> 
     <service name="ServicoWeb.servico" behaviorConfiguration="Wcf_Behavior"> 
      <endpoint name="" binding="webHttpBinding" contract="IServico" bindingConfiguration="webHttpTransportSecurity" /> 
     </service> 
    </services> 
    <bindings> 
     <webHttpBinding> 
      <binding name="webHttpTransportSecurity"> 
       <security mode="Transport" /> 
      </binding> 
     </webHttpBinding> 
    </bindings> 
    <behaviors> 
     <endpointBehaviors> 
      <behavior> 
       <webHttp automaticFormatSelectionEnabled="true" defaultBodyStyle="Bare" /> 
      </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
      <behavior name="Wcf_Behavior"> 
       <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
       <serviceDebug includeExceptionDetailInFaults="true" /> 
      </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <protocolMapping> 
     <add binding="basicHttpsBinding" scheme="https" /> 
    </protocolMapping> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" /> 
</system.serviceModel> 
... 
0

ホストファイルという名前のファイルがあります。要求を試みると、DNウィンドウがそのファイルを参照します。そのファイルにはC:\WINDOWS\System32\drivers\etcのホストファイルがあります。以下のようにホストファイルに追加します(管理モードで)。

server_ip_address  myhostname.com 
+1

を、私はちょうど新しい情報で自分の投稿を編集している:IISの作業FINEに同じウェブサイト内の他のアプリを! C#で書かれた他のWeb APIもあります。ここのように、これらはすべて正しく動作します。だから、私は問題がWindowsではないと思うが、何かinsde web.config。 – mhkgalvez