WCF-“底层连接已关闭:连接意外关闭”

发布于 2024-09-02 13:52:37 字数 1628 浏览 11 评论 0原文

在 WCF Web 服务上使用我的 Web 方法之一时,我收到了一条非常模糊的错误消息。由于该错误消息没有提供任何解释,因此我无法发表我的理论。

我相信这可能与我正在使用的返回类型有关

我有一个 Types DLL,它在 Web 服务和客户端中都被引用。这个DLL中有基类ExceptionMessages。该类有一个子类,名为 DrawingExcepions。

下面是一些代码:

public class ExceptionMessages
{
    public object[] ReturnValue { get; set; }
}

public class DrawingExceptions : ExceptionMessages
{
    private List<DrawingException> des = new List<DrawingException>();
}

public class DrawingException
{
    public Exception ExceptionMsg { get; set; }
    public List<object> Errors { get; set; }
}

使用代码:

    [OperationContract]
    ExceptionMessages createNewBom(Bom bom, DrawingFiles dfs);

    public ExceptionMessages createNewBOM(Bom bom, DrawingFiles dfs)
    {
            return insertAssembly(bom, dfs);
    }

    public DrawingExceptions insertAssembly(Bom bom, DrawingFiles dfs)
    {
        DrawingExceptions des = new DrawingExceptions();

        foreach (DrawingFile d in dfs.drawingFiles)
        {
            DrawingException temp = insertNewDrawing(bom, d);
            if (temp != null)
                des.addDrawingException(temp);

            if (d.Child != null)
                des.addDrawingException(insertAssembly(bom, d.Child));
        }

        return des;
    }

返回:

    ExceptionMessages ems = client.createNewBom(bom, currentDFS);

    if (ems is DrawingExceptions) { }

基本上,webmethod 的返回类型是 ExceptionMessages,但是我通常会发送回子类。

我唯一的想法是,是孩子造成了错误,但据我所读,这应该没有影响。有谁知道这里可能出什么问题吗?

如果需要更多信息,请询问:)

谢谢。

I'm recieving that wonderfuly ambiguous error message when using one of my webmethods on my WCF webservice. As that error message doesn't provide any explanation whatsoever allow me to post my theory.

I believe it may have something to do with the return type I'm using

I have a Types DLL which is refrenced in both the webservice and the client. In this DLL is the base class ExceptionMessages. There is a child of this class called DrawingExcepions.

Here is some code:

public class ExceptionMessages
{
    public object[] ReturnValue { get; set; }
}

public class DrawingExceptions : ExceptionMessages
{
    private List<DrawingException> des = new List<DrawingException>();
}

public class DrawingException
{
    public Exception ExceptionMsg { get; set; }
    public List<object> Errors { get; set; }
}

The using code:

    [OperationContract]
    ExceptionMessages createNewBom(Bom bom, DrawingFiles dfs);

    public ExceptionMessages createNewBOM(Bom bom, DrawingFiles dfs)
    {
            return insertAssembly(bom, dfs);
    }

    public DrawingExceptions insertAssembly(Bom bom, DrawingFiles dfs)
    {
        DrawingExceptions des = new DrawingExceptions();

        foreach (DrawingFile d in dfs.drawingFiles)
        {
            DrawingException temp = insertNewDrawing(bom, d);
            if (temp != null)
                des.addDrawingException(temp);

            if (d.Child != null)
                des.addDrawingException(insertAssembly(bom, d.Child));
        }

        return des;
    }

Returns to:

    ExceptionMessages ems = client.createNewBom(bom, currentDFS);

    if (ems is DrawingExceptions) { }

Basically the return type from the webmethod is ExceptionMessages however I would usually be sending the child class back instead.

My only idea is that it's the child that's causing the error but as far as I've read, this should have no effect. Has anyone got any ideas what could be going wrong here?

If any more info is required, just ask :)

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

放手` 2024-09-09 13:52:37

是的,这条消息很棒:)

我经常发现启用跟踪很有帮助,如

Yes, this message is great :)

I have often found it helpful to enable tracing, as described in this article. Have a look at the section called 'Recommended Settings for Deployment or Debugging'.

小糖芽 2024-09-09 13:52:37

我在返回大负载时收到此错误,结果是 DataContractSerialiser 停止中流,因为它已达到默认的 maxItemsInObjectGraph 设置,将以下内容添加到我的端点行为修复了问题。

<dataContractSerializer maxItemsInObjectGraph="2147483647" />

I was getting this error when returning a large payload, it turned out to be the DataContractSerialiser stopping mid stream as it had hit the default maxItemsInObjectGraph setting, adding the folloing to my endpoint behavour fixed the problem.

<dataContractSerializer maxItemsInObjectGraph="2147483647" />
饭团 2024-09-09 13:52:37

我遇到了同样的问题,我发现这篇文章可能是解决我的 WCF 服务出现的超时错误的方法。就我而言,史奎格的回答提供了有关潜在情况的线索。虽然增加最大有效负载的大小很容易,但这显然是一个会影响性能的选项。

就我而言,我正在上传要保存的对象图,然后将更新后的对象返回给我的客户端,以便我可以跟踪外键等。对于我的问题,问题是它如何在回程。我仔细研究了一下,发现有效负载大小扩大的根本原因是,当我向对象图中添加子对象时,这些子对象的导航属性添加了对父对象的引用,而父对象又引用了子对象,并且等等等等。

我转到我的 edmx 文件,从有问题的子对象中删除了导航属性,并且我的包大小得到了控制。

希望这对其他人有帮助!

I had the same issue and I came upon this post as a possible solution to a timeout error that my WCF service was having. In my case squig's answer offered a clue as to the underlying condition. While it's easy to up the size of the max payload, that is obviously an option with performance implications.

In my case, I'm uploading an object graph to be saved, then returning the updated object to my client so I can keep track of foreign keys, etc. For my problem the question was how could it have gotten so much bigger on the return trip. I dug around and it struck me that the root cause of the expanded payload size was that when I added a child object to my object graph, the navigation properties of those child objects added references to the parent, which had references to the child, and so on and so on.

I went to my edmx file, removed the navigation properties from the offending child objects and my package size was tamed.

Hope this helps someone else!

寻梦旅人 2024-09-09 13:52:37

我刚刚遇到了同样的问题,但是上面的答案都没有解决问题。

我带回了 LINQ 对象列表,数据库正确设置了所有关系,这导致对象自动与 LINQ 链接...这使查询无法工作。

我通过从 LINQ DBML 中删除关系解决了这个问题

I have just had the same issue however none of the answers above solved the problem.

I was bringing back a List of LINQ objects, the database has all relationships set up correctly which causes objects to be linked automatically with LINQ... This was stopping the query from working.

I solved this by removing the relationships from the LINQ DBML

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文