你好我想要用户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
}
}
答案 0 :(得分:0)
您将其设置为<add binding="wsHttpBinding" scheme="https"/>
,但在主持人中您使用的是Uri baseAddress = new Uri(http+ your site's URL);
所以将scheme="https"
更改为scheme="http"