.服务契约的定义
/* 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. jqGrid使用json实现的范例一

    qGrid 是一个用来显示网格数据的jQuery插件,通过使用jqGrid可以轻松实现前端页面与后台数据的ajax异步通信.文档比较全面,其官方网址为:http://www.trirand.com. ...

  2. webdriver的2种等待

    隐性等待是指当要查找元素,而这个元素没有马上出现时,告诉WebDriver查询Dom一定时间,默认值是0,但是设置之后,这个时间将在WebDriver对象实例整个生命周期都起作用 driver.man ...

  3. p/Invoke工具

    开源的工具 下面这个链接来下载这个工具: http://download.microsoft.com/download/f/2/7/f279e71e-efb0-4155-873d-5554a06085 ...

  4. Http消息头中常用的请求头和响应头

    作为Web开发对常用http的请求头和响应头熟悉了解一下还是很有必要的.比如请求头中Content-type指定了请求的内容,若类型是application/x-www-form-urlencoded ...

  5. java 方法(函数)

    所谓方法,就是用来解决一类问题的代码的有序组合,是一个功能模块. 一般情况下,定义一个方法的语法是: 其中: 1. 访问修饰符:方法允许被访问的权限范围, 可以是 public.protected.p ...

  6. Python将数据写入excel或者txt,读入csv格式或xls文件,写入csv(写一行空一行解决办法)

    1.写入excel,一开始不需要自己新建一个excel,会自动生成 attribute_proba是我写入的对象 import xlwt myexcel = xlwt.Workbook() sheet ...

  7. Appium使用ID进行定位

      1 使用uiautomatorviewer地获取元素ID 路径:sdk\tools\uiautomatorviewer.bat 2 脚本中增加点击事件 driver.find_element_by ...

  8. MU-MIMO学习

    设备的认证查询 https://www.wi-fi.org/product-finder 1. MU-MIMO不会增大无线的最大速度 2. MU-MIMO需要路由器和客户端同时支持 3. 当你没有或者 ...

  9. CentOS下查看最后登录的用户信息以及LOG记录

    CentOS下查看最后登录的用户信息tail /var/log/messagestail /var/log/secure 我们知道,在redhat下可以用lastlog查看各用户最后登录的信息,用la ...

  10. 《Linux内核精髓:精通Linux内核必会的75个绝技》一HACK #9 RT Group Scheduling 与RT Throttling

    HACK #9 RT Group Scheduling 与RT Throttling 本节介绍对实时进程所使用的CPU时间进行限制的功能RT Group Scheduling和RT Throttlin ...