WCF不支泛型方法<T> 何以取代Remoting wcfremoting泛型 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 比Remoting更复杂、更沉重、同样有效的RPC机制,在10年前有很多。但是你要问最近5年流行什么,对不起,他们全都被打上了“过时了”的记号。因为要适应这些年形势的因素很多。比如说服务器群中各个服务器的“无状态”通讯机制,比如说高速、轻量级握手协议,比如说支持json/xml数据对象适配,比如说脱离“拥有者公司”的官僚主义,等等。 就具体这一点东西而言,其实“支持泛型”不算什么。因为在Remoting中你必须在两端都预先部署目标类型代码,然后才能泛型中的所谓T参数反射成功。而既然需要这样,其实你可以定义一个不带泛型参数的参数的类型,它从带泛型参数最终类型来继承,这样你传送的对象的类型也就不带有泛型参数了。比如说你用json字符串来表示一个对象,然后用一个string来表示这个对象的类型,然后你自己写两句话来反序列化出这个json字符串对应的内存对象,如果你这样写过几行代码,你就不觉得泛型反射在这里算是什么重要论据。 不知wcf中是否有类似的解决办法实现 这种泛型方法? 我现在急需在service中加入泛型方法,传递的参数只会是int decimal double之类的基本类型,返回值类型也是如此。 谢谢! 如果是自定义格式的TCP服务,可以试试fastCSharpusing System;using System.Collections.Generic;namespace fastCSharp.testCase{ [fastCSharp.setup.cSharp.tcpServer(IsIdentityCommand = true, Host = "127.0.0.1", Port = 12345)] internal partial class tcpServerGeneric { [fastCSharp.setup.cSharp.tcpServer(CommandIentity = 0)] private valueType get<valueType>() { object value; return values.TryGetValue(typeof(valueType), out value) ? (valueType)value : default(valueType); } private static readonly Dictionary<Type, object> values = new Dictionary<Type, object>(); [fastCSharp.setup.testCase] private static bool testCase() { using (fastCSharp.testCase.tcpServer.tcpServerGeneric server = new fastCSharp.testCase.tcpServer.tcpServerGeneric()) { if (server.Start()) { using (fastCSharp.testCase.tcpClient.tcpServerGeneric client = new fastCSharp.testCase.tcpClient.tcpServerGeneric()) { values[typeof(int)] = 1; if (client.get<int>() != 1) return false; values[typeof(string)] = "a"; if (client.get<string>() != "a") return false; return true; } } } return false; } }} 总是见你回答问题,肯定是个大神。我想问一下, [OperationContract] public dynamic hello() { dynamic obj = 3; return obj; }像这样一个wcf方法如何才能公开呢?如果不介意可以给出代码,多谢 我以前也想用泛型+WCF 搞了2月 。。别想用这个了。。坑 问个关于Enum.parse的用法 高分求解,链接的MHT文件为中文名时,链接里的图表出错显示不了 怎样播放音频文件 FTP上传文件的一个问题,请教 下大家 急 急 急 做了一个c# WinForm 如何项目制作安装程序! 请问如何把图片存入数据库,然后读出来? c#中的数据导出 窗口转换后当前窗体关不了,求老师指点 水晶报表工具箱中的工具在那里添加啊? 如何用C#写个客户端软件,然后将选择的文件传到服务器上? C#算法编程,(资格赛) 如果你感觉自己还可以,就来试试吧 新人,大家帮看看这程序哪有问题啊,该怎么解决?
不知wcf中是否有类似的解决办法实现 这种泛型方法? 我现在急需在service中加入泛型方法,传递的参数只会是int decimal double之类的基本类型,返回值类型也是如此。 谢谢!
using System.Collections.Generic;namespace fastCSharp.testCase
{
[fastCSharp.setup.cSharp.tcpServer(IsIdentityCommand = true, Host = "127.0.0.1", Port = 12345)]
internal partial class tcpServerGeneric
{
[fastCSharp.setup.cSharp.tcpServer(CommandIentity = 0)]
private valueType get<valueType>()
{
object value;
return values.TryGetValue(typeof(valueType), out value) ? (valueType)value : default(valueType);
}
private static readonly Dictionary<Type, object> values = new Dictionary<Type, object>(); [fastCSharp.setup.testCase]
private static bool testCase()
{
using (fastCSharp.testCase.tcpServer.tcpServerGeneric server = new fastCSharp.testCase.tcpServer.tcpServerGeneric())
{
if (server.Start())
{
using (fastCSharp.testCase.tcpClient.tcpServerGeneric client = new fastCSharp.testCase.tcpClient.tcpServerGeneric())
{
values[typeof(int)] = 1;
if (client.get<int>() != 1) return false; values[typeof(string)] = "a";
if (client.get<string>() != "a") return false; return true;
}
}
}
return false;
}
}
}
[OperationContract]
public dynamic hello()
{
dynamic obj = 3;
return obj;
}
像这样一个wcf方法如何才能公开呢?如果不介意可以给出代码,多谢