WCF IIS托管的wsHttpBinding服务 - svcutil使用basicHttpBinding生成代理!

时间:2010-10-26 16:16:18

标签: wcf

我认为自己是WCF的专家,但这让我很难过。我不知道这是一个.NET Framework 4 / WCF 4的东西,它的自动配置或什么,但我得到奇怪的行为。我基本上在IIS项目中托管了WCF 4 WCF服务。这一切都工作,然后我进入并将配置从basicHttpBinding切换到wsHttpBinding。我尝试在我的消费应用程序中更新服务引用,并在生成的配置中获得basicHttpBinding输出。所以,当然,我放下并运行svcutil.exe与.svc文件相同且结果相同。这是配置文件(Blah替换了我不能公开使用的名称):

<system.web>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Windows"></authentication>
    <identity impersonate="true"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpEndpointBinding">
          <security mode="Message">
            <message clientCredentialType="Windows" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="Blah.Services.RONScheduler.BlahService.BlahDataServiceBehavior"
        name="Blah.Services.RONScheduler.FAMService">
        <endpoint address="BlahDataService" binding="wsHttpBinding" bindingConfiguration="WSHttpEndpointBinding"
          name="WSHttpEndpoint" contract="Blah.Services.RONScheduler.FAMService.IBlahDataService"> 
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Blah.Services.RONScheduler.BlahService.BlahDataServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

这是我在清除不必要的东西之前产生的结果:

<system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IBlahDataService" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost/BlahService/BlahDataService.svc"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IBlahDataService"
                contract="IBlahDataService" name="BasicHttpBinding_IBlahDataService" />
        </client>
    </system.serviceModel>

正如您所看到的那样,它忽略了配置中的wsHttpBinding设置。是什么给了什么?

2 个答案:

答案 0 :(得分:3)

您是否检查了默认协议绑定,这是WCF 4中的一项新功能

默认情况下,它们位于您的machine.config中,应该如下所示:

<system.serviceModel>
   <protocolMapping>
      <add scheme="http" binding="basicHttpBinding" bindingConfiguration="" />
      <add scheme="net.tcp" binding="netTcpBinding" bindingConfiguration=""/>
      <add scheme="net.pipe" binding="netNamedPipeBinding" bindingConfiguration=""/>
      <add scheme="net.msmq" binding="netMsmqBinding" bindingConfiguration=""/>
   </protocolMapping>

所以这有点意味着如果你要点击HTTP地址,WCF 4默认会使用basicHttpBinding

如果需要,您可以在自己的配置中更改这些绑定。

A Developer's Introduction to Windows Communication Foundation 4

中找到了这个

答案 1 :(得分:2)

根据您提供的配置,我的猜测是服务名称无效,主机回退到默认配置。

确保服务名称与实现类名称匹配。

我得出了这个结论,因为界面名称为Blah.Services.RONScheduler.FAMService.IBlahDataService,类名为Blah.Services.RONScheduler.FAMService。在FAMService之后看起来有些东西丢失了。