C# ServiceContract会话的wsHttpBinding应用程序配置

C# ServiceContract会话的wsHttpBinding应用程序配置,c#,xml,wcf,session,config,C#,Xml,Wcf,Session,Config,你好,我想使用用户SessionMode=SessionMode.Required,我了解到wcf服务必须具有wsHttpBinding,因为它支持会话。现在我制作了一个用于配置的app.config,并在windows窗体中制作了一个函数来启动服务。当我单击一个按钮并调用StartWCFServer()时,会出现以下异常: InvalidOperationException未处理 找不到与绑定为WSHttpBinding的终结点的方案https匹配的基址。注册的基址方案是[http]。 这是我

你好,我想使用用户
SessionMode=SessionMode.Required
,我了解到wcf服务必须具有
wsHttpBinding
,因为它支持会话。现在我制作了一个用于配置的
app.config
,并在windows窗体中制作了一个函数来启动服务。当我单击一个按钮并调用
StartWCFServer()
时,会出现以下异常:

InvalidOperationException未处理

找不到与绑定为WSHttpBinding的终结点的方案https匹配的基址。注册的基址方案是[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主机;
私有void StartWCFServer()
{
if(主机==null)
{
Uri baseAddress=新Uri(“http://localhost:8000/");
主机=新服务主机(类型(WCFService),基地址);
AddServiceEndpoint(typeof(IWCFService)、新的WSHttpBinding(“WSHttpBinding”)、“服务”);

host.Open();//这里您将其设置为
,但在主机中您使用的是
uribaseaddress=newuri(http+您站点的URL);


因此,将
scheme=“https”
更改为
scheme=“http”

我也会遇到同样的异常。尝试将基址部分添加到配置文件中,看看它是否工作。我将address=“”更改为address=“myhost”现在我得到了一个例外:契约需要双工,但绑定“WSHttpBinding”不支持它,或者没有正确配置以支持它。
     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
                }
        }