2017-04-02 83 views
0

我有一個REST服務。該服務需要使用http和https。 我試着在我的web.config文件中添加兩個端點。REST服務WebHttpBinding與Http和Https

找不到匹配方案HTTPS在 端點結合的WebHttpBinding基址:但是當我嘗試瀏覽我的服務通過HTTP我得到這個錯誤。註冊的基地址方案 是[http]。

找不到與綁定的WebHttpBinding端點符合計劃http的基址:

,當我試圖瀏覽通過https我得到這個錯誤。註冊的基地址方案是[https]。

如果我從我的配置文件中刪除了一個端點,那麼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

錯誤沒有改變:( –