WCF 中的复杂数据类型? [英] Complex data types in WCF?

查看:24
本文介绍了WCF 中的复杂数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试返回一个包含子对象集合的对象时遇到了问题,而子对象集合又可以包含孙子对象的集合.我收到错误消息,连接被主机强行关闭".

I've run into a problem trying to return an object that holds a collection of childobjects that again can hold a collection of grandchild objects. I get an error, 'connection forcibly closed by host'.

有什么办法可以使这个工作?我目前有一个类似这样的结构:

Is there any way to make this work? I currently have a structure resembling this:

伪代码:

Person:
IEnumerable<Order>

Order:
IEnumerable<OrderLine>

所有三个对象都具有 DataContract 属性,我想要公开的所有公共属性(包括 IEnumerable 的)都具有 DataMember 属性.

All three objects have the DataContract attribute and all public properties i want exposed (including the IEnumerable's) have the DataMember attribute.

我的服务上有多个 OperationContract,并且所有返回单个对象或对象的 IEnumerable 的方法都可以完美运行.只有当我尝试嵌套 IEnumerable 时,它​​才会变坏.同样在我的客户服务参考中,我选择了通用列表作为我的集合类型.我只是想强调一下,只有我的一个操作/方法因这个错误而失败 - 其余的都可以完美运行.

I have multiple OperationContract's on my service and all the methods returning a single object OR an IEnumerable of an object works perfectly. It's only when i try to nest IEnumerable that it turns bad. Also in my client service reference i picked the generic list as my collection type. I just want to emphasize, only one of my operations/methods fail with this error - the rest of them work perfectly.

EDIT(更详细的错误描述):

EDIT (more detailed error description):

[SocketException (0x2746): An existing connection was forcibly closed by
the remote host]
[IOException: Unable to read data from the transport connection:
An existing connection was forcibly closed by the remote host.]
[WebException: The underlying connection was closed: An unexpected
error occurred on a receive.]
[CommunicationException: An error occurred while receiving the HTTP
response to http://myservice.mydomain.dk/MyService.svc. This could
be due to the service endpoint binding not using the HTTP protocol.
This could also be due to an HTTP request context being aborted by
the server (possibly due to the service shutting down). See server
logs for more details.]

我尝试查找日志,但找不到任何日志...而且我正在使用 WSHttpBinding 和 http 端点.

I tried looking for logs but i can't find any... also i'm using a WSHttpBinding and an http endpoint.

推荐答案

注意,您需要学习如何使用 WCF 日志记录实用程序:

As a note, you need to learn how to use the WCF logging utilities:

日志信息.

配置编辑器(让设置变得轻而易举).

Config Editor (makes it a snap to setup).

跟踪查看器.太棒了.允许多个服务(客户端和服务器)进行跟踪并可以加入它们并帮助您分析所有细节.让您真正快速地找到问题的根源.(因为当出现服务器 WCF 错误时,客户端不太可能获得有用的数据.)

Trace viewer. Totally awesome. Allows multiple services (client and server) to trace and can join them and help you analyse all the details. Lets you get to the root of issues really fast. (Cause when there's a server WCF error, the client is unlikely to get useful data out.)

这篇关于WCF 中的复杂数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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