.服务契约的定义
/* 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. [LOJ2541]「PKUWC2018」猎人杀

    loj description 有\(n\)个猎人,每个猎人有一个仇恨度\(w_i\),每个猎人死后会开一枪打死一个还活着的猎人,打中每个猎人的概率与他的仇恨度成正比. 现在你开了第一枪,打死每个猎人 ...

  2. LG4719 【模板】动态dp 及 LG4751 动态dp【加强版】

    题意 题目描述 给定一棵\(n\)个点的树,点带点权. 有\(m\)次操作,每次操作给定\(x,y\),表示修改点\(x\)的权值为\(y\). 你需要在每次操作之后求出这棵树的最大权独立集的权值大小 ...

  3. Linux function: unshare

    When a new process is created with the clone() system call, a set of flags is provided which tells t ...

  4. .NET泛型解析(下)

    上一篇对.NET中的泛型进行了详细的介绍以及使用泛型的好处是什么,这篇将更加深入的去了解泛型的其他的知识点,重头戏. [1]泛型方法 上一篇我们也说过了,泛型可以是类,结构,接口,在这些泛型类型中定义 ...

  5. Linux 解压zip need PK compat. v4.5 (can do v2.1)

    p7z 当使用7zip压缩大于4G的文件后,在linux下解压时,出现下面的提示,无法解压: [root@localhost root]# unzip Wrestlemania20.zip Archi ...

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

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

  7. servlet中获取配置文件中的参数.

    web.xml (添加init-param) <?xml version="1.0" encoding="UTF-8"?> <web-app ...

  8. gSOAP:C++编写服务器端

    1.编写头文件cal.h: //gsoap ns service name: calc //gsoap ns service style: rpc //gsoap ns service encodin ...

  9. java程序控制KETTLE JOB的执行

    有时候我们想在java程序中触发远程服务器上kettle job的执行,并且获得执行结果.kettle的carte提供了远程执行job和transfer的功能. 我使用的kettle是6.1版本,部署 ...

  10. Shell脚本的调试方法

    Shell脚本的调试方法 Shell提供了一些用于调试脚本的选项,如下所示: -n    读一遍脚本中的命令但不执行,用于检查脚本中的语法错误 -v    一边执行脚本,一边将执行过的脚本命令打印到标 ...