none
为啥WCF在IIS下的配置没有生效? RRS feed

  • 问题

  • 我在WCF配置里打开了GZIP,配置如下,

    <system.serviceModel>

        <bindings>
          <customBinding>
            <binding name="HJLite_Client_CustomBinding" closeTimeout="01:00:00"
              openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00">
              <binaryMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647"
                maxSessionSize="2147483647" compressionFormat="GZip" />
              <httpTransport maxBufferPoolSize="524288000" maxReceivedMessageSize="2147483647"
                maxBufferSize="2147483647" />
            </binding>
          </customBinding>
        </bindings>
        <client>
          <endpoint address="http://localhost/HJLite.Client.WcfService/Implement/CInventoryImplementWCF.svc" binding="customBinding" bindingConfiguration="HJLite_Client_CustomBinding" contract="HJLite.Client.WcfService.ICInventoryInterfaceWCF" name="customBinding_CInventoryImplementWCF" behaviorConfiguration="" />
        </client>

        <behaviors>
          <serviceBehaviors>
            <behavior name="">
              <!-- 为避免泄漏元数据信息,请在部署前将以下值设置为 false -->
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
              <!-- 要接收故障异常详细信息以进行调试,请将以下值设置为 true。在部署前设置为 false 以避免泄漏异常信息 -->
              <serviceDebug includeExceptionDetailInFaults="false"/>
              <dataContractSerializer maxItemsInObjectGraph="655360000" />
              <serviceTimeouts transactionTimeout="10:00:00" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <protocolMapping>
          <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      </system.serviceModel>


    问题是,发布到IIS后,通过SvcUtil.exe生成的config文件中只有简单的basicHttpBinding,这样就导致我客户端和服务端协议不一致,连不上了,请问IIS上是否还有什么开关没打开么?

                <basicHttpBinding>
                    <binding name="BasicHttpBinding_ISys_UserInterfaceWCF" />
                </basicHttpBinding>

      
    2017年2月27日 8:59

答案

  • 嗨,

    在Debug情况下,你的服务运行后svcUtil.exe 生成的config文件是对的么?

    根据你的描述,你的第一段配置文件应该是WCF Service端的,但是并没有配置Service, 只是定义里Client节点,如果是Service端的,配置文件应该像下面的:

      <system.serviceModel>
        <services>
          <service name="WCFAsync.WCFAsync">
            <endpoint address="" binding="customBinding" bindingConfiguration="HJLite_Client_CustomBinding" contract="WCFAsync.IWCFAsync"/>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>
        <bindings>
          <customBinding>
            <binding name="HJLite_Client_CustomBinding" closeTimeout="01:00:00"
              openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00">
              <binaryMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647"
                maxSessionSize="2147483647" compressionFormat="GZip" />
              <httpTransport maxBufferPoolSize="524288000" maxReceivedMessageSize="2147483647"
                maxBufferSize="2147483647" />
            </binding>
          </customBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <protocolMapping>
            <add binding="basicHttpsBinding" scheme="https"/>
        </protocolMapping>    
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
      </system.serviceModel>

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • 已标记为答案 asuras 2017年2月28日 3:06
    2017年2月28日 2:36
    版主

全部回复

  • 嗨,

    在Debug情况下,你的服务运行后svcUtil.exe 生成的config文件是对的么?

    根据你的描述,你的第一段配置文件应该是WCF Service端的,但是并没有配置Service, 只是定义里Client节点,如果是Service端的,配置文件应该像下面的:

      <system.serviceModel>
        <services>
          <service name="WCFAsync.WCFAsync">
            <endpoint address="" binding="customBinding" bindingConfiguration="HJLite_Client_CustomBinding" contract="WCFAsync.IWCFAsync"/>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
          </service>
        </services>
        <bindings>
          <customBinding>
            <binding name="HJLite_Client_CustomBinding" closeTimeout="01:00:00"
              openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00">
              <binaryMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647"
                maxSessionSize="2147483647" compressionFormat="GZip" />
              <httpTransport maxBufferPoolSize="524288000" maxReceivedMessageSize="2147483647"
                maxBufferSize="2147483647" />
            </binding>
          </customBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <protocolMapping>
            <add binding="basicHttpsBinding" scheme="https"/>
        </protocolMapping>    
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
      </system.serviceModel>

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • 已标记为答案 asuras 2017年2月28日 3:06
    2017年2月28日 2:36
    版主
  • 通常情况下,我会重新启动应用程序池和IIS
    2017年2月28日 11:07