.服务契约的定义
/* Copyright (c) 2014 HaiHui Software Co., Ltd. All rights reserved
*
* Create by huanglc@holworth.com at 2014-10-14 10:09:00
*
*/ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using Framework;
using System.Collections;
using Contract.Domain; namespace Contract.IService
{ ///<summary>
///协议内容 Interface
///</summary>
[ServiceKnownType("GetKnownTypes", typeof(Framework.IService.KnownTypesProvider))]
[ServiceContract]
public interface IBasAgreementService : IEntityService<BasAgreement>
{ } }
.数据提供者 provider 解析的作用,你就知道哪些东西是属于服务的范畴,哪些属于数据的范畴
#if !NET_2_0
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.Serialization; namespace Framework.IService
{
public static class KnownTypesProvider
{
static object syncObj = new object();
public static Type[] GetKnownTypes(ICustomAttributeProvider attributeTarget)
{
//get contract types from service assembly:DataContractAttribute="Contract.IService.ITestService"
Type serviceContractType = (Type)attributeTarget;
Assembly callerAssembly = serviceContractType.Assembly; if (KnowAssemblys.Count == )//First Init
LoadAppDomainTypes();
GetTypeFromAssembly(callerAssembly);
return KnowTypes.ToArray();
} public static Type[] GetKnownTypes()
{
Assembly callerAssembly = Assembly.GetCallingAssembly(); if (KnowAssemblys.Count == )//First Init
LoadAppDomainTypes();
GetTypeFromAssembly(callerAssembly);
return KnowTypes.ToArray();
} private static void LoadAppDomainTypes()
{
if (KnowAssemblys.Count == )//First Init
{
//CurrentDomain
List<Assembly> typeAssemblys = new List<Assembly>();
Assembly[] domainAssemblys = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly asm in domainAssemblys)
if (asm.FullName.IndexOf("Contract") > - || asm.FullName.IndexOf("Framework,") > - || asm.FullName.IndexOf("Domain")>-)//IsContract?
typeAssemblys.Add(asm); //Type serializableType = typeof(SerializableAttribute);
foreach (Assembly typeAssembly in typeAssemblys)
{
GetTypeFromAssembly(typeAssembly);
}
}
} static Type dataContractType = typeof(DataContractAttribute);
private static void GetTypeFromAssembly(Assembly callerAssembly)
{
if (!KnowAssemblys.Contains(callerAssembly.FullName))//Not loaded
{
lock (syncObj)
{
if (!KnowAssemblys.Contains(callerAssembly.FullName))//Not loaded(DOUBLE CHECK)
{
//filter by DataContractAttribute
Type[] exportedTypes = callerAssembly.GetExportedTypes(); foreach (Type type in exportedTypes)
if (Attribute.IsDefined(type, dataContractType, false))// || Attribute.IsDefined(type, serializableType, false))
//if (type.Namespace.IndexOf("Contract.")==0)
KnowTypes.Add(type); KnowAssemblys.Add(callerAssembly.FullName);
}
}
}
} private static List<Type> knowTypes;
private static List<Type> KnowTypes
{
get
{
if (knowTypes == null)
{
lock (syncObj)
{
if (knowTypes == null)
{
knowTypes = new List<Type>(); //bug fixed!
knowTypes.Add(typeof(string[]));
knowTypes.Add(typeof(object[]));
knowTypes.Add(typeof(System.Collections.Hashtable));
knowTypes.Add(typeof(System.Data.DataSet));
}
}
}
return knowTypes;
}
} private static List<String> knowAssemblys;
private static List<String> KnowAssemblys
{
get
{
if (knowAssemblys == null)
{
lock (syncObj)
{
if (knowAssemblys == null)
knowAssemblys = new List<String>();
}
}
return knowAssemblys;
}
}
}
}
#endif

wcf已知类型 known type的更多相关文章

  1. WCF 已知类型和泛型解析程序 KnownType

    数据协定继承 已知类型和泛型解析程序 Juval Lowy 下载代码示例 自首次发布以来,Windows Communication Foundation (WCF) 开发人员便必须处理数据协定继承方 ...

  2. WCF技术剖析之十三:序列化过程中的已知类型(Known Type)

    原文:WCF技术剖析之十三:序列化过程中的已知类型(Known Type) [爱心链接:拯救一个25岁身患急性白血病的女孩[内有苏州电视台经济频道<天天山海经>为此录制的节目视频(苏州话) ...

  3. C# 序列化过程中的已知类型(Known Type)

    WCF下的序列化与反序列化解决的是数据在两种状态之间的相互转化:托管类型对象和XML.由于类型定义了对象的数据结构,所以无论对于序列化还是反序列化,都必须事先确定对象的类型.如果被序列化对象或者被反序 ...

  4. WCF数据契约代理和已知类型的使用

    using Bll; using System; using System.CodeDom; using System.Collections.Generic; using System.Collec ...

  5. WCF 之 已知类型(KnownType)

    已知类型(Known types)允许在服务契约中使用多态的行为,在服务操作中暴露基本类型.将已知类型(known types)相关到基本类型(基类类型)自身;特定操作;整个服务契约采用属性声明或者配 ...

  6. java基础 File与递归练习 使用文件过滤器筛选将指定文件夹下的小于200K的小文件获取并打印按层次打印(包括所有子文件夹的文件) 多层文件夹情况统计文件和文件夹的数量 统计已知类型的数量 未知类型的数量

    package com.swift.kuozhan; import java.io.File; import java.io.FileFilter; /*使用文件过滤器筛选将指定文件夹下的小于200K ...

  7. WCF中数据契约之已知类型的几种公开方式

    WCF中传输的数据不想传统的面向对象编程,它只传递了一些对象的属性,但是自身并不知道自己属于什么对象,所以,他没有子类和父类的概念,因而也就没有Is-a的关系,所以在WCF中,如果想维持这种继承关系, ...

  8. 已知json类型根据类型封装集合

    1编写帮助类根绝url得到json public static string Post(string url) { string strURL = url; //创建一个HTTP请求 HttpWebR ...

  9. C#在父窗口中调用子窗口的过程(无法访问已释放的对象)异常,不存在从对象类型System.Windows.Forms.DateTimePicker到已知的托管提供程序本机类型的映射。

    一:C#在父窗口中调用子窗口的过程(无法访问已释放的对象)异常 其实,这个问题与C#的垃圾回收有关.垃圾回收器管 理所有的托管对象,所有需要托管数据的.NET语言(包括 C#)都受运行库的 垃圾回收器 ...

随机推荐

  1. 深入理解java虚拟机,并发方面

    1 1,java线程模型,和内存模型像似,但没有很强硬的关联 2,工作内存和主内存的交互操作,lock,unlock,read,load,use,assign,store,write 2,volati ...

  2. python2用pip进行安装时报错Fatal error in launcher: Unable to create process using '"'

    win7下python3和python2共存环境 用pip安装一个包执行pip2 install xxx的时候报错Fatal error in launcher: Unable to create p ...

  3. Intellij Idea上Spring Boot编译报错:Error:(3, 32) java: 程序包org.springframework.boot不存在

    很尴尬,为了使用Spring Boot的Initializr,特意下了个Intellij Idea,刚按提示新建一个Spring Boot的Maven项目后,就出现红叉叉了.因为IDE是新的,开始是M ...

  4. 两个不错点电影ED2000资源

    http://simplecd.me/ http://www.ed2000.com/ http://www.2tu.cc/ http://www.mp4ba.com/ http://www.ddyy. ...

  5. 【linux】head&&tail

    命令:     head[-n][文件名]                                    tail[-n][-f][文件名] 形式:     -n  行数 (显示前几行)    ...

  6. Python自然语言处理(1):初识NLP

    由于我们从美国回来就是想把医学数据和医学人工智能的事认真做起来,所以我们选择了比较扎实的解决方法,想快速出成果的请绕道.我们的一些解决方法是:1.整合公开的所有医学词典,尽可能包含更多的标准医学词汇: ...

  7. struts2学习(2)struts2核心知识

    一.Struts2 get/set 自动获取/设置数据 根据上一章.中的源码继续. HelloWorldAction.java中private String name,自动获取/设置name: pac ...

  8. Hive 安装操作

    本篇为安装篇较简单: 前提:1: 安装了hadoop-1.0.4(1.0.3也可以)正常运行2:安装了hbase-0.94.3, 正常运行 接下来,安装Hive,基于已经安装好的hadoop,步骤如下 ...

  9. memcached配置 (初级)以及测试

    一.memcached安装 memcached依赖 $ sudo apt-get install libevent-dev   安装memcached服务 $ sudo apt-get install ...

  10. thinkphp5中Indirect modification of overloaded element of XXX has no effect的解决办法

    最近在使用Thinkphp5做foreach循环嵌套的时候报错:Indirect modification of overloaded element of XXX has no effect,网上搜 ...