周转基金.服务通用方法 [英] WCF. Service generic methods

查看:14
本文介绍了周转基金.服务通用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 wcf 服务中使用泛型方法?

How can I use generic methods in wcf service?

我写了这段代码:

[OperationContract]
void AddItem<T>(T item);

但我收到以下错误:

类型T"不能作为架构类型导出,因为它是一个开放的泛型类型.如果所有泛型参数类型都是实际类型,则只能导出泛型类型.

Type 'T' cannot be exported as a schema type because it is an open generic type. You can only export a generic type if all its generic parameter types are actual types.

推荐答案

你根本做不到.这是不可能的,因为肥皂不支持这一点.请参阅此文章,其中提到了如何绕过泛型,通过创建一个中间本地对象,在调用 WCF 操作之前调用该对象并转换该对象.

You simply can't. It's not possible to do that, as soap does not support this. See this article, which mentions how to get around generics, by creating an intermediate local object that is called and casts the object before calling the WCF operation.

这篇关于周转基金.服务通用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆