小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

silverlight調(diào)用wcf報錯“給定關(guān)鍵字不在數(shù)據(jù)字典中”

 實力決定地位 2011-05-25
一、             KeyNotFoundException,給定關(guān)鍵字不在字典中
         可通過使用啟用silvlerlight功能的WCF服務。當然,普通的WCF也是可以使用在SL中的,只不過在配置上比較繁瑣。
二、             無法序列化
1.         第一類錯誤:無法從未標記有 DataContractAttribute 或 SerializableAttribute 的類型繼承類型……
         這類錯誤可以通過加上如上提示的屬性解決,但更多時候需要檢查是否調(diào)用的是“啟用silvlerlight功能的WCF服務”。
 
2.         第二類錯誤:嘗試對參數(shù) http:/// 進行序列化時出錯。
         同第一類。也有可能是代碼缺少必要的屬性。
 
3.         第三類錯誤:格式化程序嘗試對消息反序列化時引發(fā)異常: 嘗試對參數(shù) http:/// 進行反序列化時出錯。
         同第一類。也可從修改reference.cs中的屬性的namespace解決。
 
4.         第四類錯誤:“Element”命名空間“***”中的“***”并非所需元素。所需元素應為“__identity”
同第一類。
 
PS: 參數(shù)類或者返回值類不能包含任何方法和構(gòu)造函數(shù)。不然也會出現(xiàn)不能序列化。     
三、             MarshalByRefObject
如果調(diào)用的是普通的WCF,則極有可能在reference.cs產(chǎn)生的客戶端代碼中,有System.MarshalByRefObject。這應該是微軟WCF的一個BUG。因為SL中根本就沒有這個類。查看WEBSERVICE,客戶端代碼中自動生成了MarshalByRefObject。那么參照WS,我們也可以生成一個供WCF使用的MarshalByRefObject。如下:
 view plaincopy to clipboardprint?
[System.Runtime.Serialization.KnownTypeAttribute(typeof(DbParameter))]  
    [System.Runtime.Serialization.KnownTypeAttribute(typeof(SqlParameter))]  
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]  
    [System.Runtime.Serialization.DataContractAttribute(Name = "MarshalByRefObject", Namespace = "http:///")]  
    public abstract partial class MarshalByRefObject : object, System.ComponentModel.INotifyPropertyChanged  
    {  
 
        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;  
 
        protected void RaisePropertyChanged(string propertyName)  
        {  
            System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;  
            if ((propertyChanged != null))  
            {  
                propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));  
            }  
        }  
    } 
[System.Runtime.Serialization.KnownTypeAttribute(typeof(DbParameter))]
    [System.Runtime.Serialization.KnownTypeAttribute(typeof(SqlParameter))]
    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "3.0.0.0")]
    [System.Runtime.Serialization.DataContractAttribute(Name = "MarshalByRefObject", Namespace = "http:///")]
    public abstract partial class MarshalByRefObject : object, System.ComponentModel.INotifyPropertyChanged
    {
        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
        protected void RaisePropertyChanged(string propertyName)
        {
            System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
            if ((propertyChanged != null))
            {
                propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
            }
        }
    }

四、             SqlParameter傳值的問題
         SqlParameter這個參數(shù)比較特殊,在SL調(diào)用webservice的時候是支持的,在SL調(diào)用WCF的時候是不支持。
         如果一定要傳這類參數(shù),可以自己創(chuàng)建一個SqlParameter類,在SL端和WCF端均調(diào)用即可。
 
五、             異步轉(zhuǎn)同步
         WCF默認不支持同步調(diào)用,需要開發(fā)者自己拓展。見http://blog.csdn.net/luminji/archive/2010/02/02/5281944.aspx。
六、             典型配置ServiceReferences.ClientConfig
<configuration>
  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="CustomBinding_IYiPinPropWCF">
          <binaryMessageEncoding />
          <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
            <extendedProtectionPolicy policyEnforcement="Never" />
          </httpTransport>
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8894/YiPinPropWCF.svc" binding="customBinding"
        bindingConfiguration="CustomBinding_IYiPinPropWCF" contract="ServiceReferenceYiPinProp.IYiPinPropWCF"
        name="CustomBinding_IYiPinPropWCF" />
    </client>
  </system.serviceModel>
</configuration>
 
6:典型配置Web.config
<system.serviceModel>
  <behaviors>
   <serviceBehaviors>
    <behavior name="YiPin.QuestionsDbSL.Web.YiPinPropWCFBehavior">
     <serviceMetadata httpGetEnabled="true" />
     <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
   </serviceBehaviors>
  </behaviors>
  <bindings>
   <customBinding>
    <binding name="customBinding0">
     <binaryMessageEncoding />
     <httpTransport/>
    </binding>
   </customBinding>
  </bindings>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  <services>
   <service behaviorConfiguration="YiPin.QuestionsDbSL.Web.YiPinPropWCFBehavior"
    name="YiPin.QuestionsDbSL.Web.YiPinPropWCF">
    <endpoint address="" binding="customBinding" bindingConfiguration="customBinding0"
     contract="YiPin.QuestionsDbSL.Web.IYiPinPropWCF" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
   </service>
  </services>
 </system.serviceModel>
 

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多