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#)都受运行库的 垃圾回收器 ...
随机推荐
- MacBook下配置android adb命令使用环境
想在Mac下使用android adb命令,常用的两种配置方式: 在MacBook下配置adb命令环境(方法一) 1.下载并安装IDE (android studio) 人性化的安装,直接点击下一步下 ...
- TCP建立连接的三次握手和TCP连接断开的四次挥手
1. TCP建立连接的3次握手 2. TCP断开连接的四次挥手 [注意]中断连接端可以是Client端,也可以是Server端. 图3—Client端主动发起关闭连接请求 1. 假设Client端主动 ...
- 提高ASP.NET页面载入速度的方法
前言 本文是我对ASP.NET页面载入速度提高的一些做法,这些做法分为以下部分: 目录 1.采用 HTTP Module 控制页面的生命周期. 2.自定义Response.Filter得到输出流str ...
- errno.h的数字对应的字符串错误
#ifndef _I386_ERRNO_H #define _I386_ERRNO_H #define EPERM 1 /* Operation not permitted */ #define EN ...
- [CLPR] 卷积神经网络的结构
本文翻译自: http://www.codeproject.com/Articles/16650/Neural-Network-for-Recognition-of-Handwritten-Digi ...
- APN与VPDN的主要区别
VPDN APN 安全性 二次认证,加密 一次认证,没有加密 企业成本 高 低 对GGSN要求 可接受动态配置LNS参数信息,对GGSN性能影响小. 静态配置GRE隧道参数,性能影响较大,部分厂家对G ...
- 【转】java中创建对象的方法
有4种显式地创建对象的方式: 1.用); System.out.println("call default constructor"); } public Customer(Str ...
- java.lang.NumberFormatException:For input string:"undefined"
在将字符串转换为数字时导致此错误,解决此问题的思路: 1.添加 try catch语句 2.判断字符串是否为数字,将介绍java中判断字符串是否为数字的方法的几种方法 发生错误的代码: java.la ...
- while循环-for循环
while true: 无限循环语句 break跳出循环,当count=1000的时候结束循环 count是结束当前循环'''count = 0while True: print("coun ...
- 利用PHP实现页面跳转同时POST传参,CURL不行
function payto(){ echo "<form style='display:none;' id='form1' name='form1' method='post' ac ...