【发布时间】:2014-11-27 07:23:06
【问题描述】:
你好,我想用户 SessionMode = SessionMode.Required,我读到 wcf 服务必须有 wsHttpBinding 因为支持会话。现在我制作了一个app.config 用于配置,并以Windows 形式制作了一个函数来启动服务。当我单击一个按钮并调用 StartWCFServer() 时,我得到了这个异常:
InvalidOperationException was unhandled
Could not find a base address that matches scheme https for the endpoint with binding WSHttpBinding. Registered base address schemes are [http].
这是我的代码:
App.config
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehaviour" name="WCF_Server.WCFService">
<endpoint address="" behaviorConfiguration="web" binding="wsHttpBinding" bindingConfiguration="wsHttpBindings" contract="WCF_Server.IWCFService"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
<serviceDebug httpsHelpPageEnabled="true" httpHelpPageEnabled="true" includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="wsHttpBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<bindings>
<wsHttpBinding>
<binding name="wsHttpBindings">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
StartWCFServer()
ServiceHost host;
private void StartWCFServer()
{
if (host == null)
{
Uri baseAddress = new Uri("http://localhost:8000/");
host = new ServiceHost(typeof(WCFService), baseAddress);
host.AddServiceEndpoint(typeof(IWCFService), new WSHttpBinding("wsHttpBinding"), "Services");
host.Open();//<-- Exception here
}
}
【问题讨论】: