WCF。服务泛型方法 [英] WCF. Service generic methods

查看:138
本文介绍了WCF。服务泛型方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用通用的方法,在WCF服务?

我写这篇code:

  [OperationContract的]
无效的AddItem< T>(T项目);

不过,我收到以下错误:


  

键入'T'不能导出为一个模式类型,因为它是一个开放的泛型类型。如果所有的泛型参数类型的实际类型只能导出一个泛型类型。



解决方案

您根本不能。这是不可能做到这一点,因为肥皂不支持这一点。看到这个<一个href=\"http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/79585667-6b97-4ce4-93fa-3a4dcc7a9b86\">article,其中提到如何解决仿制药,通过创建调用,调用WCF操作之前蒙上对象中间本地对象。

How can I use generic methods in wcf service?

I wrote this code:

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

But I receive the following Error:

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.

解决方案

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.

这篇关于WCF。服务泛型方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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