2011-02-13 112 views
1

我正在嘗試向我的Silverlight客戶端添加一個WCF端點行爲。不過,我在運行時遇到以下錯誤:Silverlight客戶端是否支持WCF行爲?

Unrecognized element 'behaviors' in service reference configuration. 
Note that only a subset of the Windows Communication Foundation 
configuration functionality is available in Silverlight. 

WCF端點確實無法在Silverlight中擴展嗎?我ServiceReferences.ClientConfig文件列表如下展示如何,我想添加一個名爲MyBehaviorExtention的一個推廣:

<configuration> 

    <system.serviceModel> 

     <extensions> 
      <behaviorExtentions> 
       <add 
        name="MyBehaviorExtention" 
        type="MyTest, 
          MyBehaviorExtention, 
          Version=1.0.0.0, 
          Culture=neutral, 
          PublicKeyToken=null" /> 
      </behaviorExtentions> 
     </extensions> 

     <behaviors> 
      <endpointBehaviors> 
       <behavior name="MyBehavior"> 
        <MyBehaviorExtention /> 
       </behavior> 
      </endpointBehaviors> 
     </behaviors> 

     <bindings> 
      <basicHttpBinding> 
       <binding 
        name="MyWebServicePortBinding" 
        maxBufferSize="2147483647" 
        maxReceivedMessageSize="2147483647"> 
        <security mode="None" /> 
       </binding> 
      </basicHttpBinding> 
     </bindings> 

     <client> 
      <endpoint 
       name="MyWebServicePort" 
       address="http://localhost:8080/MyService" 
       binding="basicHttpBinding" 
       bindingConfiguration="MyWebServicePortBinding" 
       contract="MyServiceReference.MyWebService" 
       behaviorConfiguration="MyBehavior" /> 
     </client> 

    </system.serviceModel> 

</configuration> 

回答

0

如果這不是在你的服務器端的web.config走呢? ServiceReferences.ClientConfig應包含有關WebService參考信息的信息,例如端點地址等。它包含服務的地址,並在編譯生成的.xap文件中進行編譯。

這裏是我的web.config的樣本,我使用行爲擴展:

<extensions> 
     <behaviorExtensions> 
     <add name="silverlightFaults" type="MyApp.Web.Services.SilverlightFaultBehavior, MyApp.Web"/> 
     </behaviorExtensions> 
    </extensions> 

    <behaviors> 
     <endpointBehaviors> 
     <behavior name="SilverlightFaultBehavior"> 
      <silverlightFaults /> 
     </behavior> 
     </endpointBehaviors> 
     <serviceBehaviors> 
     <behavior name=""> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 

這是我所需要的。我的ServiceRefeferences.ClientConfig只包含端點地址。它僅包含Windows Communication Foundation(WCF)客戶端配置的子集

+0

我的服務器是Java - 所以沒有服務器端web.config。在客戶端上,我只是試圖添加一個消息檢查器作爲行爲的端點。我能夠以編程方式(在客戶端)完成它,並想知道爲什麼我無法通過配置來完成它。 – Naresh 2011-02-14 20:11:24