wcf已知类型 known type
.服务契约的定义
/* 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的更多相关文章
- WCF 已知类型和泛型解析程序 KnownType
数据协定继承 已知类型和泛型解析程序 Juval Lowy 下载代码示例 自首次发布以来,Windows Communication Foundation (WCF) 开发人员便必须处理数据协定继承方 ...
- WCF技术剖析之十三:序列化过程中的已知类型(Known Type)
原文:WCF技术剖析之十三:序列化过程中的已知类型(Known Type) [爱心链接:拯救一个25岁身患急性白血病的女孩[内有苏州电视台经济频道<天天山海经>为此录制的节目视频(苏州话) ...
- C# 序列化过程中的已知类型(Known Type)
WCF下的序列化与反序列化解决的是数据在两种状态之间的相互转化:托管类型对象和XML.由于类型定义了对象的数据结构,所以无论对于序列化还是反序列化,都必须事先确定对象的类型.如果被序列化对象或者被反序 ...
- WCF数据契约代理和已知类型的使用
using Bll; using System; using System.CodeDom; using System.Collections.Generic; using System.Collec ...
- WCF 之 已知类型(KnownType)
已知类型(Known types)允许在服务契约中使用多态的行为,在服务操作中暴露基本类型.将已知类型(known types)相关到基本类型(基类类型)自身;特定操作;整个服务契约采用属性声明或者配 ...
- java基础 File与递归练习 使用文件过滤器筛选将指定文件夹下的小于200K的小文件获取并打印按层次打印(包括所有子文件夹的文件) 多层文件夹情况统计文件和文件夹的数量 统计已知类型的数量 未知类型的数量
package com.swift.kuozhan; import java.io.File; import java.io.FileFilter; /*使用文件过滤器筛选将指定文件夹下的小于200K ...
- WCF中数据契约之已知类型的几种公开方式
WCF中传输的数据不想传统的面向对象编程,它只传递了一些对象的属性,但是自身并不知道自己属于什么对象,所以,他没有子类和父类的概念,因而也就没有Is-a的关系,所以在WCF中,如果想维持这种继承关系, ...
- 已知json类型根据类型封装集合
1编写帮助类根绝url得到json public static string Post(string url) { string strURL = url; //创建一个HTTP请求 HttpWebR ...
- C#在父窗口中调用子窗口的过程(无法访问已释放的对象)异常,不存在从对象类型System.Windows.Forms.DateTimePicker到已知的托管提供程序本机类型的映射。
一:C#在父窗口中调用子窗口的过程(无法访问已释放的对象)异常 其实,这个问题与C#的垃圾回收有关.垃圾回收器管 理所有的托管对象,所有需要托管数据的.NET语言(包括 C#)都受运行库的 垃圾回收器 ...
随机推荐
- linux sort 多列正排序,倒排序
转载:https://segmentfault.com/a/1190000005713784 sort是在Linux里非常常用的一个命令,管排序 sort将文件的每一行作为一个单位,相互比较,比较原则 ...
- ballerina 学习二十三 扩展ballerina
扩展ballerina 目前有三种方式: 扩展client connector的包 (数据库访问,基础设施,api) 扩展server listenner 绑定为不同的协议 添加新的注解到baller ...
- 使用IAR编译STM8S 怎样生产烧录文件
IAR编译后能够生成的烧录文件格式有4中,例如以下 第一种是Motorola,其生成文件和STVD生成烧录文件.s19格式一样的,即能够通用 另外一种是16进制,keil等等常都用到的. 第三种是 ...
- 适合Centos Web服务器的iptables规则
适合Centos Web服务器的iptables规则IPT="/sbin/iptables"$IPT --delete-chain$IPT --flush$IPT -P INPUT ...
- QT:QByteArray和QByteArray、char *(转)
//常用参数类型:char *字符串, QByteArray字符数组, QString字符串//需要转换:char * ---转--- QByteArray ---需要调用QByteArray类的构造 ...
- LCD RGB 控制技术讲解 — 时钟篇(上)
时序图 下面是LCD RGB 控制的典型时序图 天啊,一下就上这玩意,怎么看??? 其实要解释上面的时序图,我们还需要了解一些LCD的显示过程.所以现在只是有个印象,稍后我们详细讲解. LCD显示流 ...
- ACM-Team Tic Tac Toe
我的代码: #include <bits/stdc++.h> using namespace std; int main() { char a[3][3]; int i,j=0; for( ...
- PY安装模块
Python安装失败原因 0环境 , pip版本一般为 7.x , 所以一般需要先升级pip版本 , 也就是执行 ```shellpython -m pip install --upgrade pip ...
- jsp的session完成登陆功能
login.jsp: <%@ page language="java" import="java.util.*" contentType="te ...
- 3_bootsrap布局容器
3.布局容器 BootStrap必须需要至少一个布局容器,才能为页面内容进行封装和方便的样式控制. 相当于一个画板. 帮助手册位置:全局CSS样式------->概览------->布局容 ...