Bil*_*lla 12 c# asp.net wcf web-services webhttpbinding
我正在尝试使用https和http作为网站.该网站有.svc文件,它们充当REST服务并从JavaScript调用.
我的配置:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="AjaxBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MyServiceBehaviour">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service behaviorConfiguration="MyServiceBehaviour" name="MyService.Lookups">
<endpoint address="" behaviorConfiguration="AjaxBehavior"
binding="webHttpBinding" bindingConfiguration="httpWebBinding" contract="MyService.Lookups" >
</endpoint>
<endpoint address="" behaviorConfiguration="AjaxBehavior"
binding="webHttpBinding" bindingConfiguration="httpsWebBinding" contract="MyService.Lookups" >
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="httpsWebBinding">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" />
</security>
</binding>
<binding name="httpWebBinding">
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
浏览https://myserver/services/Lookups.svc/Hello给出
找不到与绑定WebHttpBinding的端点的scheme http匹配的基址.注册的基地址方案是[https]
浏览http://myserver/services/Lookups.svc/Hello给出
找不到与绑定WebHttpBinding的端点的方案https匹配的基址.注册的基地址方案是[http]
如果我删除任何一个端点它的工作原理.删除配置bindingConfiguration="httpWebBinding"了HTTPS工作的端点的示例,
如何使其与HTTP和HTTPS一起使用?截至目前,我可以通过删除一个端点来使用http或https.
Referred 如何在一个web.config中为http和https组合WCF服务配置?以及如何设置HTTP和HTTPS WCF 4 RESTful服务?
注意:在IIS中,有两个网站,一个在http上侦听,另一个在https上侦听.两者在物理文件夹中共享相同的代码
更新:截至目前,我删除了端点,它的工作原理.但我担心的是删除使用behaviourConfiguration配置的endpoing对我来说不是很好的解决方案.
这适用于http和https
<services>
<service behaviorConfiguration="MyServiceBehaviour" name="MyService.Lookups">
</service>
</services>
Run Code Online (Sandbox Code Playgroud)
小智 5
我重新创建了您的场景,并使用您的web.config为我的测试服务配置端点.您的配置正常并且工作正常.不适合您的部分可能是您在IIS中的https配置.确保您已启用https访问您的服务.如果您使用Visual Studio中的IISExpress进行测试,则左键单击您的项目,然后在属性窗口(视图 - >属性窗口)中选择SSL Enabled = True.