簡體   English   中英

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

[英]WCF IIS-hosted wsHttpBinding service - svcutil generates proxy with basicHttpBinding!

我認為自己是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設置一樣。 是什么賦予了?

您是否檢查了默認協議綁定,這是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

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

Windows Communication Foundation 4的開發人員簡介中找到此內容

給定您提供的配置,我的猜測是服務名稱無效並且主機回退到默認配置。

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

之所以得出這個結論,是因為接口名稱是Blah.Services.RONScheduler.FAMService.IBlahDataService ,而類名稱是Blah.Services.RONScheduler.FAMService FAMService之后FAMService缺少一些東西。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM