Regarding this thread I've opened earlier:
Storing WCF rest request data with SQL Server stored procedure
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);
}
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
is a 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.
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.
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.
Any solutions?
Thanks
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.