简体   繁体   English

从WCF函数返回DataContract时,出现此错误:“接收HTTP响应时发生错误”

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

Here are my data contracts: 这是我的数据合同:

[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; }
}

I have an OperationContract that takes a "ClaimInformation" and returns a list of "Claim." 我有一个OperationContract,它需要一个“ ClaimInformation”并返回一个“ Claim”列表。 Which is just two integers and an image that is broken down into a stream. 这只是两个整数,并且图像分解为流。

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

ProcessDocument calls a method in a class. ProcessDocument调用类中的方法。

public List<Claim> ProcessDocument(ClaimInformation ClaimInfo)
{
    List<Claim> FinishedClaimList = new List<Claim>();

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

    return FinishedClaimList;
}

That method is too large for me to post here. 该方法太大,我无法在此处发布。 But it's just this: 只是这样:

public List<Claim> ProcessDocument(ClaimInformation ClaimInfo)
    {

Inside of the method, it creates a new "Claim" and adds it to the "ClaimList." 在方法内部,它将创建一个新的“声明”并将其添加到“声明列表”。

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

And finally, this is how I'm calling it all: 最后,这就是我所说的一切:

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));

I'm just creating a new client for the service and then instantiating a new ClaimInformation DataContract. 我只是为该服务创建一个新客户端,然后实例化一个新的ClaimInformation DataContract。 I set the ImageNames property, which is just a list of strings and then I add an integer to the TotalPages. 我设置了ImageNames属性,它只是一个字符串列表,然后将一个整数添加到TotalPages中。

Any ideas on what I'm doing wrong here? 对我在这里做错的任何想法吗?

That's a pretty generic exception in WCF so you'll need to enable WCF tracing to get more detailed info. 在WCF中,这是一个非常普通的例外,因此您需要启用WCF跟踪以获取更多详细信息。

Just guessing but look at this MSDN forum thread where the list contained complex objects that exceeded the default internal object limits in WCF. 只是猜测而已,请看一下此MSDN论坛线程 ,该列表包含的复杂对象超出了WCF中的默认内部对象限制。 Once you enable WCF tracing, you should have a better idea of what's going on. 启用WCF跟踪后,您应该对发生的事情有了更好的了解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM