2017-04-02 15 views
0

私はRESTサービスを持っています。このサービスはhttpとhttpsで動作する必要があります。 web.configファイルに2つのエンドポイントを追加しようとしました。RESTサービスHttpとHttpsを使ったWebHttpBinding

はWebHttpBindingバインディングを持つ エンドポイントのスキームのhttpsと一致するベースアドレスが見つかりませんでした:私はHTTP経由で私のサービスを閲覧しようとすると、しかし、私はこのエラーを取得します。登録ベースアドレス体系 は[http]です。

と私はHTTPS経由で閲覧しようとすると、私はこのエラーを取得:

はWebHttpBindingバインディングとエンドポイントのスキームはhttpに一致するベースアドレスが見つかりませんでした。登録ベースアドレス方式は[https]です。

私の設定ファイルからエンドポイントの1つを削除すると、httpサービスとhttpsサービスがうまく動作します。 私はこのリンクをチェックしました:WebHttpBinding with Http and Https しかし、設定ファイルからエンドポイントを削除すると、httpとhttpsの両方のサービスがWebブラウザでエラーなく実行されます。しかし、私がこのサービスで自分の方法(残りのクライアントツールを介して)を呼び出そうとすると、次のようになります。

500内部サーバーエラー。

どうすればこのサービスをhttpとhttpsでエラーなく実行できますか?

私の設定ファイルは次のようである:ここ

<system.serviceModel> 
<protocolMapping> 
    <add scheme="http" binding="webHttpBinding" bindingConfiguration="webHttpBinding"/> 
    <add scheme="https" binding="webHttpBinding" bindingConfiguration="webHttpsBinding"/> 
</protocolMapping> 
<bindings> 
    <webHttpBinding> 
    <binding name="webHttpBinding"> 
     <security mode="None"> 
     <transport clientCredentialType="None" proxyCredentialType="None" /> 
     </security> 
    </binding> 
    <binding name="webHttpsBinding"> 
     <security mode="Transport"> 
     <transport clientCredentialType="None" proxyCredentialType="None" /> 
     </security> 
    </binding> 
    </webHttpBinding> 
</bindings> 
<services> 
    <service name="MyProject.MyService" behaviorConfiguration="serviceBehavior"> 
    <endpoint address="" binding="webHttpBinding" behaviorConfiguration="web" bindingConfiguration="webHttpBinding" contract="MyProject.IMyService" /> 
    <endpoint address="" binding="webHttpBinding" behaviorConfiguration="web" bindingConfiguration="webHttpsBinding" contract="MyProject.IMyService" /> 
    <!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />--> 
    <!--<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>--> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="serviceBehavior"> 
     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
     <serviceAuthorization serviceAuthorizationManagerType="MyProject.RestAuthorizationManager, MyProject"/> 
    </behavior> 
    </serviceBehaviors> 
    <endpointBehaviors> 
    <behavior name="web"> 
     <webHttp/> 
    </behavior> 
    </endpointBehaviors> 
</behaviors> 
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>  

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/>  
    <directoryBrowse enabled="true"/> 
    </system.webServer> 
+0

この問題を解決できましたか? – Mese

答えて

0

は両方httphttpsをサポートしているために、サンプルweb.configです。私はあなたの問題を解決することを願っています:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 

    <appSettings> 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" /> 
    </appSettings> 

    <system.web> 
    <compilation debug="true" targetFramework="4.5.2" /> 
    <httpRuntime targetFramework="4.5.2" /> 
    </system.web> 

    <system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
     <binding name="SoapBinding" /> 
     </basicHttpBinding> 
     <basicHttpsBinding> 
     <binding name="SecureSoapBinding" /> 
     </basicHttpsBinding> 

     <webHttpBinding> 
     <binding name="RestBinding" /> 
     <binding name="SecureRestBinding"> 
      <security mode="Transport" /> 
     </binding> 
     </webHttpBinding> 

     <mexHttpBinding> 
     <binding name="MexBinding" /> 
     </mexHttpBinding> 
     <mexHttpsBinding> 
     <binding name="SecureMexBinding" /> 
     </mexHttpsBinding> 
    </bindings> 

    <client /> 

    <services> 
     <service behaviorConfiguration="ServiceBehavior" name="Interface.Core"> 
     <endpoint address="soap" binding="basicHttpBinding" bindingConfiguration="SoapBinding" name="Soap" contract="Interface.ICore" /> 
     <endpoint address="soap" binding="basicHttpsBinding" bindingConfiguration="SecureSoapBinding" name="SecureSoap" contract="Interface.ICore" /> 
     <endpoint address="" behaviorConfiguration="Web" binding="webHttpBinding" bindingConfiguration="RestBinding" name="Rest" contract="Interface.ICore" /> 
     <endpoint address="" behaviorConfiguration="Web" binding="webHttpBinding" bindingConfiguration="SecureRestBinding" name="SecureRest" contract="Interface.ICore" /> 
     <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="MexBinding" name="Mex" contract="IMetadataExchange" /> 
     <endpoint address="mex" binding="mexHttpsBinding" bindingConfiguration="SecureMexBinding" name="SecureMex" contract="IMetadataExchange" /> 
     </service> 
    </services> 

    <behaviors> 
     <endpointBehaviors> 
     <behavior name="Web"> 
      <webHttp helpEnabled="true" defaultBodyStyle="Bare" defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" /> 
     </behavior> 
     </endpointBehaviors> 

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

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

    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true" /> 
    <directoryBrowse enabled="false" /> 
    </system.webServer> 

</configuration> 
+0

エラーは変更されていません:( –

関連する問題