2013-04-07 28 views
2

我想創建一個需要會話支持的WCF服務,所以我在web.config中添加了一個部分來啓用wsHttpBinding。但是當我在WCF測試客戶端測試服務並檢查配置時,它似乎採用了默認的自動生成的配置而不是我自己的配置。使用wsHttpBinding,WCF忽略我的web.config

見我的配置:

<?xml version="1.0"?> 
<configuration> 
<system.web> 

<compilation debug="true" targetFramework="4.0" /> 
</system.web> 
    <system.serviceModel> 

<behaviors> 
    <serviceBehaviors> 

    <behavior> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 
    </behavior>  
    </serviceBehaviors> 
</behaviors> 

<services> 
    <service name="UserService"> 
    <endpoint address="" binding="wsHttpBinding" contract="ICenterPlaceUserService" /> 
    </service> 
</services> 

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 

而結果:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
<system.serviceModel> 
    <bindings> 
     <basicHttpBinding> 
      <binding name="BasicHttpBinding_ICenterPlaceUserService" sendTimeout="00:05:00" /> 
     </basicHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:57418/L1.WCF/CenterPlaceUserService.svc" 
      binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICenterPlaceUserService" 
      contract="ICenterPlaceUserService" name="BasicHttpBinding_ICenterPlaceUserService" /> 
    </client> 
</system.serviceModel> 

我錯過了什麼?

+0

我假設您正在爲您的項目添加服務引用。如果這是真的,那麼你之後是否更新了項目中的服務參考? – Justin 2013-04-07 23:18:27

+0

到目前爲止,我沒有在任何項目中使用該服務。我使用的WCF測試客戶端,當我從* .svc.cs文件中按下調試時會自動打開。 – 2013-04-07 23:21:14

+0

您是否嘗試保存該項目,關閉Visual Studio並重試? – Justin 2013-04-07 23:27:02

回答

11

<service>屬性的name屬性必須具有服務類的完全限定名。否則,它將被忽略,並且您將看到您所看到的行爲:默認綁定用於服務(basicHttpBinding)。

<services> 
    <service name="TheNamespaceOfYourClass.UserService"> 
    <endpoint address="" 
       binding="wsHttpBinding" 
       contract="TheNamespaceOfYourContract.ICenterPlaceUserService" /> 
    </service> 
</services> 
+0

完美無瑕地工作。謝謝 ! – 2013-04-08 00:35:11

+2

我希望我可以多投票:) – misha 2014-01-24 16:04:15