【问题标题】:wsHttpBinding app config for ServiceContract sessionsServiceContract 会话的 wsHttpBinding 应用程序配置
【发布时间】: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
                }
        }

【问题讨论】:

    标签: c# xml wcf session config


    【解决方案1】:

    在这里您将其设置为&lt;add binding="wsHttpBinding" scheme="https"/&gt;,但在主机中您使用的是Uri baseAddress = new Uri(http+ your site's URL);

    所以把scheme="https"改成scheme="http"

    【讨论】:

    • 我得到同样的异常。
    • 尝试将基地址部分添加到您的配置文件中,看看它是否有效。
    • 我将 address="" 更改为 address="myhost",现在我得到异常:合同需要 Duplex,但绑定 'WSHttpBinding' 不支持它或未正确配置以支持它。
    猜你喜欢
    • 1970-01-01
    • 2011-02-23
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-09
    • 1970-01-01
    相关资源
    最近更新 更多