Silverlight调用WCF若干问题汇总

一、             KeyNotFoundException,给定关键字不在字典中

         可通过使用启用silvlerlight功能的WCF服务。当然,普通的WCF也是可以使用在SL中的,只不过在配置上比较繁琐。

二、             无法序列化

1.         第一类错误:无法从未标记有 DataContractAttribute SerializableAttribute 的类型继承类型……

         这类错误可以通过加上如上提示的属性解决,但更多时候需要检查是否调用的是“启用silvlerlight功能的WCF服务”。

 

2.         第二类错误:尝试对参数 http://tempuri.org/ 进行序列化时出错。

         同第一类。也有可能是代码缺少必要的属性。

 

3.         第三类错误:格式化程序尝试对消息反序列化时引发异常: 尝试对参数 http://tempuri.org/ 进行反序列化时出错。

         同第一类。也可从修改reference.cs中的属性的namespace解决。

 

4.         第四类错误:“Element”命名空间“***”中的“***”并非所需元素。所需元素应为“__identity

同第一类。

 

PS: 参数类或者返回值类不能包含任何方法和构造函数。不然也会出现不能序列化。     

三、             MarshalByRefObject

如果调用的是普通的WCF,则极有可能在reference.cs产生的客户端代码中,有System.MarshalByRefObject。这应该是微软WCF的一个BUG。因为SL中根本就没有这个类。查看WEBSERVICE,客户端代码中自动生成了MarshalByRefObject。那么参照WS,我们也可以生成一个供WCF使用的MarshalByRefObject。如下:

 

四、             SqlParameter传值的问题

         SqlParameter这个参数比较特殊,在SL调用webservice的时候是支持的,在SL调用WCF的时候是不支持。

         如果一定要传这类参数,可以自己创建一个SqlParameter类,在SL端和WCF端均调用即可。

 

五、             异步转同步

         WCF默认不支持同步调用,需要开发者自己拓展。见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>

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值