关于c#:从WCF函数返回DataContract时,我收到此错误:“接收HTTP响应时发生错误”

While returning a DataContract from a WCF function, I'm getting this error: “An error occurred while receiving the HTTP response”

这是我的数据合同:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[DataContract]
public class Claim : IDisposable
{
    [DataMember]
    public int ClaimID { get; set; }

    [DataMember]
    public Stream ClaimImage { get; set; }

    [DataMember]
    public int PageNumber { get; set; }

    public void Dispose()
    {
        if (ClaimImage != null)
        {
            ClaimImage.Close();
            ClaimImage = null;
        }
    }
}

[DataContract]
public class ClaimInformation
{
    [DataMember]
    public List<string> Documents { get; set; }

    [DataMember]
    public int TotalPages { get; set; }
}

我有一个OperationContract,它带有一个" ClaimInformation"并返回一个" Claim"列表。 这只是两个整数,并且图像分解为流。

1
2
[OperationContract]
List<Claim> ProcessDocument(ClaimInformation ClaimInfo);

ProcessDocument调用类中的方法。

1
2
3
4
5
6
7
8
9
public List<Claim> ProcessDocument(ClaimInformation ClaimInfo)
{
    List<Claim> FinishedClaimList = new List<Claim>();

    Document doc = new Document();
    FinishedClaimList = doc.ProcessDocument(ClaimInfo);

    return FinishedClaimList;
}

该方法太大,无法在此处发布。 只是这样:

1
2
public List<Claim> ProcessDocument(ClaimInformation ClaimInfo)
    {

在方法内部,它将创建一个新的"声明"并将其添加到"声明列表"。

1
ClaimList.Add(new Claim { ClaimID = ClaimID, ClaimImage = this.GetStream(newdoc.FullName), PageNumber = pageNum });

最后,这就是我所说的一切:

1
2
3
4
5
6
OCREngine.IEngine engine = new OCREngine.EngineClient();
OCREngine.ClaimInformation CI = new ClaimInformation();
CI.Documents = ImageNames;
CI.TotalPages = cc.lbClaims.Items.Count;

ClaimList.Add(engine.ProcessDocument(CI));

我只是为该服务创建一个新客户端,然后实例化一个新的ClaimInformation DataContract。 我设置了ImageNames属性,它只是一个字符串列表,然后将一个整数添加到TotalPages中。

对我在这里做错的任何想法吗?


这是WCF中的一个非常普通的例外,因此您需要启用WCF跟踪以获取更多详细信息。

只是猜测而已,请看一下此MSDN论坛线程,其中的列表包含的复杂对象超出了WCF中的默认内部对象限制。 启用WCF跟踪后,您应该对发生的事情有了更好的了解。