2017-04-02 46 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

错误没有改变:( –