通过WCF服务实体框架(没有IIS) [英] Entity Framework through WCF service (without IIS)
问题描述
对于这个线程我已经打开前面:
Regarding this thread I've opened earlier:
我有与一个方法,得到了 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屋!