2010-10-26 111 views
2

我認爲自己在WCF方面非常專業,但這讓我很難過。我不知道這是一個.NET Framework 4/WCF 4的東西,它是自動配置還是什麼,但我得到奇怪的行爲。我基本上有一個在IIS項目中託管的WCF 4 WCF服務。這一切工作,然後我去了,並從basicHttpBinding配置切換到wsHttpBinding。我試圖更新我的消費應用程序中的服務引用,並在生成的配置中獲取basicHttpBinding輸出。所以,當然,我放下並運行svcutil.exe重複.svc文件和相同的結果。這是配置文件(布拉赫取代,我不能公開使用的名字):WCF IIS託管的wsHttpBinding服務 - svcutil使用basicHttpBinding生成代理!

<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> 

這是我得到生成的內容之前,我清理掉unncessary東西:

<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設置。是什麼賦予了?

回答

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

+0

對,我忘了那個。好像配置應該覆蓋這個不是?您應該能夠使用config覆蓋defqaualts,否則整個配置系統都會中斷。 – 2010-10-26 17:46:22

+0

「指南」指出:「或者如果您只想在應用程序範圍內覆蓋它,則可以在應用程序/ Web配置文件中覆蓋此部分。」 – 2010-10-26 18:00:30

+0

這就是無效。 – 2010-10-26 18:00:47

2

給你提供的配置,我的猜測是,該服務的名稱是無效的,主機將退回到默認配置。

確保服務名稱與實現類名稱相匹配。

我得出這個結論是因爲接口名稱是Blah.Services.RONScheduler.FAMService.IBlahDataService,類名是Blah.Services.RONScheduler.FAMService。看起來FAMService之後有什麼遺漏。