通过WCF服务实体框架(没有IIS) [英] Entity Framework through WCF service (without IIS)

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

问题描述

对于这个线程我已经打开前面:

Regarding this thread I've opened earlier:

与SQL Server存储过程存储WCF其余请求数据

我有与一个方法,得到了 myRequest 参数

I have a simple interface in my WCF service with one method which gets a myRequest parameter

public interface IService
{
    [OperationContract]
    string MyOperation(myRequest request);
}

当我从客户端发布数据,内容类型是应用程序/ JSON ,所以请求主体的汽车deserialise到 myRequest 对象。

When I'm posting the data from the client, the content type is application/json, so the request body auto deserialise into myRequest object.

myRequest WCF DataContract

[DataContract]
public class myRequest

{
    string id;
    string Name;

    [DataMember]
    public string Name { get; set; }
    [DataMember]
    public string Id { get; set; }

}

public string MyOperation(myRequest request)
{
    if (request != null) {
        Contact contact = new Contact();
        contact.Id = Int32.Parse(request.Id);
        contact.DisplayName = request.Name;

        ContentContext db = new ContentContext();
        db.Contacts.Add(contact);
        db.SaveChanges();

        return "ok";
    }

    SetResponseHttpStatus(HttpStatusCode.InternalServerError);
    return null;
}

和finaly,托管服务:

And finaly, hosting the service:

public class ProgramBL {
    public static void StartServer()
        {

            ServiceHost streamer = new ServiceHost(typeof(DataStreaming.StreamService));


            streamer.Open();
            Console.WriteLine("Service up and running at:");
            foreach (var ea in streamer.Description.Endpoints)
            {
                Console.WriteLine(ea.Address);
            }

            Program._StreamerHost = streamer;
        }
}



_StreamerHost 程序类的静态成员。

当我试图通过<使用EF $通过控制台/应用托管C $ C> WCF休息服务。
当我试图做到这一点 - 客户端总是得到 400错误的请求响应

When I try to use the EF through WCF rest service hosted by Console/Application. When I'm trying to do it - the client gets always 400 Bad Request response.

另一件事 - 我创建了一个新的项目数据库模型解决方案, WCF 服务是另一个项目,所以我增加了数据库模型项目,服务项目refrence。为了更好地实现这个我必须安装并添加refrence到的NuGet Entityframe工作包。

Another thing - I created a new project in the solution for the database model, the WCF service is another project, so I added refrence of the database model project to the service project. To achive this I had to install and add a refrence to the Nuget Entityframe work package.

任何解决方案?

感谢

推荐答案

行,所以我解决了这个问题。

Ok so I solved the problem.

我只能在服务项目中已经安装了的NuGet 实体框架库(我用的是建库的数据库项目)。
我已经安装上的数据库项目的NuGet 实体框架+添加了的connectionString 来后服务的App.config 似乎一切都OK。

I have installed the NuGet Entity framework library only at the service project (I used the built in library at the database project). After I have installed the NuGet Entity framework on the database project + added the connectionString to the service App.config everything seems to be OK.

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

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