我有个服务。我可以用http浏览它的svc文件。但是,我无法通过https访问它。我需要对它进行一些配置更改吗?下面是一个示例配置文件
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<client>
<endpoint address="http://localhost/Sum_Wcf/Service1.svc" binding="webHttpBinding"
behaviorConfiguration="EndPointBehavior" contract="SumServiceReference.IService1" name="WebHttpBinding_Well" />
</client>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webScriptEndpoint>
<standardEndpoint name="" crossDomainScriptAccessEnabled="true">
</standardEndpoint>
</webScriptEndpoint>
</standardEndpoints>
<behaviors>
<endpointBehaviors>
<behavior name="EndPointBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>这是服务器端的配置文件。客户端元素在那里,因为它是一个演示应用程序,我在同一个应用程序中也有一个客户端应用程序,用于测试目的。
发布于 2014-08-21 17:36:58
WCF 4.0引入了默认端点、绑定和行为的概念。开箱即用,无需向配置文件添加任何内容,您将在.svc文件的位置获得一个默认端点,其默认绑定为basicHttpBinding。basicHttpBinding的默认安全模式是"None",所以即使其他配置都正确,我也不期望您能够通过SSL来浏览服务。
所以,首先是您的配置文件。您已经定义了客户端端点-如果您的服务正在调用另一个服务,那么您只需要在您的服务配置中使用这些端点,但它看起来并不是这样。您需要的是服务端点(默认情况下您有一个端点,但是您想要webHttpBinding,而不是basicHttpBinding。
现在,如果您想坚持使用默认值(根据需要进行覆盖),您可以尝试如下所示:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding>
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"
aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webScriptEndpoint>
<standardEndpoint name="" crossDomainScriptAccessEnabled="true" />
</webScriptEndpoint>
</standardEndpoints>
<behaviors>
<endpointBehaviors>
<behavior>
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="webHttpBinding" scheme="https" />
</protocolMapping>
这将为webHttpBindng设置一个默认配置(通过省略<binding>元素上的name属性),将securityMode设置为“传输”-这意味着使用该配置和webHttpBinding的任何服务都将使用您定义的绑定配置。
这同样适用于行为-默认情况下,指定的配置将用于端点,因为省略了name属性。
最后一部分是<protocolMappings>部分-在这里您将告诉应用程序使用webHttpBinding来传输https。
您仍然可以像在WCF 3/3.5中那样显式定义端点。
我不确定(因为我没有使用SSL with WCF,或者webHttpBinding ),但是你可能也需要一个证书才能做到这一点,但是你可以尝试上面的方法,看看它是否能让你朝着正确的方向前进。
另外,请看一下我在对您的问题的评论中链接到的article,或者到谷歌搜索结果的链接以获取其他信息。
发布于 2014-08-21 14:30:53
您需要添加具有基本basichttpbinding标记和添加<security mode="Transport"/>的绑定xml标记
当然,您可以使用其名称https下面的名称来绑定所有配置:
<basicHttpBinding>
<binding name="https">
<security mode="Transport" />
</binding>
</basicHttpBinding>https://stackoverflow.com/questions/25418487
复制相似问题