我有服务。我可以用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>
这是服务器端配置文件。 客户端元素在那里,因为它是一个演示应用程序,我也在同一个应用程序中有一个客户端应用程序,用于测试目的。
答案 0 :(得分:1)
WCF 4.0引入了默认端点,绑定和行为的概念。开箱即用,无需在配置文件中添加任何内容,您将在.svc文件的位置获得默认端点,默认绑定为basicHttpBinding
。 basicHttpBinding
的默认安全模式为“无”,因此即使其他所有内容都已正确配置,我也不希望您能够通过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
设置默认配置(通过省略name
元素上的<binding>
属性),将securityMode
设置为“传输” - 这意味着使用带有webHttpBinding
的配置的任何服务都将使用您定义的绑定配置。
这同样适用于行为 - 默认情况下将为端点使用指定的配置,因为省略了name
属性。
最后一部分是<protocolMappings>
部分 - 此处您告诉应用程序使用webHttpBinding
进行传输https
。
您仍然可以像在WCF 3 / 3.5中那样明确定义端点。
我不确定(因为我没有在WCF上使用SSL,或webHttpBinding
就此问题),但您可能还需要证书才能这样做,但您可以尝试以上操作,看看是否它会让你朝着正确的方向前进。
另外,请查看我在您对您的问题的评论中链接到的article,或者链接到Google搜索结果以获取更多信息。
答案 1 :(得分:0)
您需要在其中添加带有basichttpbinding标记的绑定xml标记,并在其中添加<security mode="Transport"/>
当然,您可以使用名称https:
下面的名称来绑定所有配置 <basicHttpBinding>
<binding name="https">
<security mode="Transport" />
</binding>
</basicHttpBinding>