WCF - 实体框架 - ERR_CONNECTION_RESET [英] WCF - Entity Framework - ERR_CONNECTION_RESET

查看:309
本文介绍了WCF - 实体框架 - ERR_CONNECTION_RESET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的WCF服务有问题。这里是

  [OperationContract] 
[WebGet(UriTemplate =/ needs,ResponseFormat = WebMessageFormat.Json) ]
列表< CustomerNeed> getAllCustomerNeeds();

当我进入调用此服务的页面时,我收到此错误

  GET http:// localhost:666 / rest / Service1.svc / needs net :: ERR_CONNECTION_RESET 
/ pre>

当我尝试返回一个字符串而不是列表时,它的工作原理。



CustomerNeed是通过EntityFramework从我的数据库生成的类。



在我的服务中,我只调用另一个类中的其他方法;

  public List< CustomerNeed> getAllCustomerNeeds()
{
var needs = from cn in db.CustomerNeeds
select cn;

列表< CustomerNeed> list = new List< CustomerNeed>();

foreach(需要客户需求的cusN)
{
list.Add(cusN);
}
返回列表;
}

也许是因为我的表中有一个外键CustomerNeed? p>

当我做LINQ to entity导入我的数据库时,是否必须导入由于多对多关系而创建的表?

解决方案

我将建议您创建一个简单的自定义类,代表您的CustomerNeeds数据库实体,在服务器端启动此对象并传递给客户端应用程序。它可以帮助你避免这个问题,并且推荐的方式来传递WCF服务的数据。



在这种情况下,你需要执行下一步:
1)创建一个公共类CustomerNeeds并用DataContract属性标记它。例如:

  [DataContract] 
public class CustomerNeeds
{
[DataMember]
public SomeDataType PropertyName {get; set;}
}

2)在服务上启动此对象,更改返回数据类型getAllCustomerNeeds()方法从实体类到新创建的CustomerNeed类,并将此数据传递给clien



而且这些都是。


I got a problem with my WCF service. Here is the

    [OperationContract]
    [WebGet(UriTemplate = "/needs", ResponseFormat = WebMessageFormat.Json)]
    List<CustomerNeed> getAllCustomerNeeds();

When I go on the page which call this service, I got this error

GET http://localhost:666/rest/Service1.svc/needs net::ERR_CONNECTION_RESET

When I'm trying to return a string instead of a List, it works.

CustomerNeed is a class generate from my database via EntityFramework.

In my service, I'm only calling an other method which is in an other class;

    public List<CustomerNeed> getAllCustomerNeeds()
    {
        var needs = from cn in db.CustomerNeeds
                    select cn;

        List<CustomerNeed> list = new List<CustomerNeed>();

        foreach (CustomerNeed cusN in needs)
        {
            list.Add(cusN);
        }
        return list;
    }

Maybe is it because I have a foreign key in my table CustomerNeed ?

When I do "LINQ to entities" to import my database, do I have to import tables that were created because of many to many relation ?

解决方案

I will recommend you to create a simple custom class which will represent your CustomerNeeds database entity, initiate this object on the server side and pass to the client application. It can help you to avoid this problem and also it is recommended way to transfer data accross the WCF services.

In this case you need to do the next steps: 1) Create a public class CustomerNeeds and mark it with the DataContract attribute. For example:

[DataContract]
public class CustomerNeeds 
{
   [DataMember]
   public SomeDataType PropertyName {get; set;}
}

2) Initiate this object on the service, change return datatype in getAllCustomerNeeds() method from the entity class to the newly created class CustomerNeed and pass this data to the clien

And that`s all.

这篇关于WCF - 实体框架 - ERR_CONNECTION_RESET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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