Regarding this thread I've opened earlier:
关于我之前打开的这个帖子:
Storing WCF rest request data with SQL Server stored procedure
使用SQL Server存储过程存储WCF休息请求数据
I have a simple interface in my WCF
service with one method which gets a myRequest
parameter
我的WCF服务中有一个简单的接口,其中一个方法获取myRequest参数
public interface IService
{
[OperationContract]
string MyOperation(myRequest request);
}
When I'm posting the data from the client, the content type is application/json
, so the request body auto deserialise into myRequest
object.
当我从客户端发布数据时,内容类型是application / json,因此请求主体自动反序列化为myRequest对象。
myRequest
is a WCF
DataContract
:
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;
}
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
its a static member of the Program
class.
_StreamerHost是Program类的静态成员。
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.
当我尝试使用由控制台/应用程序托管的EF到WCF休息服务时。当我尝试这样做时 - 客户端始终获得400 Bad Request响应。
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.
另一件事 - 我在数据库模型的解决方案中创建了一个新项目,WCF服务是另一个项目,因此我将数据库模型项目的参考添加到服务项目中。为了实现这个目标,我必须安装并添加对Nuget Entityframe工作包的引用。
Any solutions?
Thanks
1 个解决方案
#1
Ok so I solved the problem.
好的,我解决了这个问题。
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.
我只在服务项目中安装了NuGet Entity框架库(我在数据库项目中使用了内置库)。在数据库项目上安装NuGet Entity框架后,将connectionString添加到服务App.config,一切似乎都没问题。
#1
Ok so I solved the problem.
好的,我解决了这个问题。
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.
我只在服务项目中安装了NuGet Entity框架库(我在数据库项目中使用了内置库)。在数据库项目上安装NuGet Entity框架后,将connectionString添加到服务App.config,一切似乎都没问题。