我如何返回从WCF合同接口的参考? [英] How do I return a reference to an interface from a WCF contract?

查看:154
本文介绍了我如何返回从WCF合同接口的参考?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WCF服务。我可以返回一个具体的类没有问题,但返回的接口的引用会导致以下问题。

I have a WCF service. I can return a concrete class without a problem, but returning a reference to an interface causes the following issue.

的CommunicationException
套接字连接被中止。

CommunicationException occurred "The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:59.2030000'."

当我尝试从WCF服务得到一个类的实例,就会出现此:

This occurs when I try to get an instance of a class from a WCF service:

//create the connection
ChannelFactory<IService> _ChannelFactory = new ChannelFactory<IService>(_EndpointName);
IService _ServiceProxy = _ChannelFactory.CreateChannel();

//communication exception thrown here
ITestInterface okcomputer = _ServiceProxy.GetTest();



IService和ITestInterface都正常OperationContract的属性和等。该服务具有属性:[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]

IService and ITestInterface have all the normal OperationContract attributes and such. The Service has the attribute: [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]

除此之外,类和接口都没有什么特别的。

other than that, the classes and interfaces are nothing special.

我觉得有一些特殊的技巧从WCF接口返回一个类接口,否则我不会有这个问题..有什么诀窍?

I feel like there is some special trick to returning a class interface from a WCF interface, otherwise I wouldn't be having this problem.. What's the trick?

推荐答案

您不能返回一个接口,直到永远。它怎么会被序列化?

You cannot return an interface, ever. How would it be serialized?

接口是关于行为。行为不序列化,唯一的数据。

Interfaces are about behavior. Behavior is not serialized, only data.

这篇关于我如何返回从WCF合同接口的参考?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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