【发布时间】:2015-12-23 21:50:03
【问题描述】:
我正在尝试将 WCF 项目配置为同时使用 HTTPS 和 HTTP。
我已经设法让它在我的服务器上运行(HTTPS 和 HTTP)——当我远程调试时(使用 Chrome 的扩展程序“Advanced Rest Client”)可以完美运行,但我不断收到“错误 500 System.ServiceModel.ServiceActivationException”在我的 localhost 环境中。
我附上了我的代码,请注意我只尝试更改 "Behavior_Users"(只是想弄清楚),但我的所有接口都需要这个 HTTP + HTTPS 功能。
这是我的 Web.config:
<bindings>
<webHttpBinding>
<binding name="basicWebBinding">
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
<binding name="secureWebBinding">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" httpsHelpPageEnabled="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="Behavior_Users">
<webHttp defaultOutgoingResponseFormat="Json" defaultBodyStyle="Bare"/>
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpBinding" scheme="http"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<services>
<service name="TakesApp.MainWCF.Users">
<endpoint behaviorConfiguration="Behavior_Users" binding="webHttpBinding" bindingConfiguration="basicWebBinding" contract="TakesApp.MainWCF.IUsers">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint behaviorConfiguration="Behavior_Users" binding="webHttpBinding" bindingConfiguration="secureWebBinding" contract="TakesApp.MainWCF.IUsers">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</service>
</services>
</system.serviceModel>
</configuration>
这是我的方法:
[OperationContract]
[WebInvoke(Method = "*", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
System.ServiceModel.Channels.Message Register(Stream body);
希望你们能帮助我,我尝试了 2 天的正确答案,但没有运气。
非常感谢!!!
更新:仍然没有。考虑简单地给它一个不同的配置来调试和发布。我尝试了每种配置组合。当托管在服务器上时,它可以同时使用 HTTPS 和 HTTP,但它会在我的 localhost 环境中故障转移 POST。 WCF 很烂。
【问题讨论】:
-
你能把你的代码只减少到相关部分吗?
-
完成,希望我没有删除任何相关部分。谢谢
-
我也遇到了类似的问题
标签: .net wcf web-config wcf-binding