zoukankan      html  css  js  c++  java
  • 日志 20071221(WCF,using keyword)

    1.程序运行报错:
       Could not find default endpoint element that references contract 'ITenderTopicList' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
     看报错的意思,是找不到契约'ITenderTopicList'对应的EndPoint。难道是我的配置文件有问题?我看了一眼,明明有下面的配置信息:
     <endpoint address="http://xingyk:4072/WCFService/WCFService.svc"
       binding="basicHttpBinding" bindingConfiguration="BufferedHTTP"
       contract="WCFService.BitAEC5.TenderBidService.ITenderTopicList"
       name="ITenderTopicList" />
     后来,注意到提示中的契约名称为'ITenderTopicList'而不是'WCFService.BitAEC5.TenderBidService.ITenderTopicList',几经辗转才试出了究竟。原来,以前我写代码的时候,都是把服务器端已经写好的ServiceContract程序集自动拷贝到客户端,而我自己在定义ServiceContract的时候,从来没有设置过其ConfigurationName属性。这样的话,这个属性实际上被设置为服务类型的全名称(含名字空间)。而今天我的客户端程序包括Contract都是SvcUtil自动生成的,并且我运行svcutil的时候没有指定其namespace参数,所以生成的Contract如代码段1:
    //代码段1

    [System.CodeDom.Compiler.GeneratedCodeAttribute(
    "System.ServiceModel""3.0.0.0")]
    [System.ServiceModel.ServiceContractAttribute(ConfigurationName
    ="ITenderTopicList")]
    public interface ITenderTopicList
    {
       
    //里面内容略去
    }

    参照我上面在配置文件中所写的contract="WCFService.BitAEC5.TenderBidService.ITenderTopicList",两者无法匹配,所以报错。现在我在调用SvcUtil的时候一般会戴上/n参数,这样省去了不少麻烦。

    2.自己对DataContract的理解还很肤浅,尚不清楚什么情况下需要为自己的DataContract自定义SerialLizer。在自己的项目中用到一个DataContract,里面只有两个DataMember,一个是int型,一个是byte[],发现客户端不能正确接收(客户端得到的对象两个属性都没有赋值)。后来我把原本为byte[]类型的那个DataMember改为了String类型(base64编码),客户端的接收就正常了。先把自己的开发进度赶完吧,这里的疑问留下来,回头再看。

    3.using关键字的一个古怪限制
    先不说这样的编程风格好不好,但我们确实可以这样使用using:
    Class1 instance = new Class1();
    using (instance)
    { //省略代码 }
    也就是说,我们可以在外面声明一个变量,然后用using(...)语句进行修饰。但如果想同时修饰多个变量的话,变量的声明必须放到using语句的内部,也就是说,下面的写法是不合法的:
    Class1 instance1 = new Class1();
    Class1 instance2 = new Class1();
    using (instance1, instance2)
    { //省略代码 }
    你必须这样写才能通过编译:
    using (Class1 instance1 = new Class1(), instance2 = new Class2())
    { //省略代码 }


  • 相关阅读:
    在Android中使用Handler和Thread线程
    getCacheDir用法
    OAuth协议
    android开发参考网站
    常用的地址
    LayoutInflater获取方式
    java for map
    ubuntu12.04+nginx+apc
    ubuntu12.04 + dropbox
    yii + 获取 control + action
  • 原文地址:https://www.cnblogs.com/xingyukun/p/1010280.html
Copyright © 2011-2022 走看看