- Blog

Keep it simple

Starting with C# WCF SOAP services and EntityFramework: Lessons learned

written on 5 November 2016
I just started to develop a self-hosting WCF SOAP service using EntityFramework for serialization (with a MSSQL database backend). This service will later be accessed by a PHP SoapClient. Let me summarize some experiences here: * You can create C# WCF contracts from a WSDL by using: `svcutil your.wsdl` * Services are instanced for each request by default. You can change this by using following attribute on you service implementation: * `[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]` * This allows you to pass parameters to your service * To allow non-Administrator users to run the service, execute this on the cmd as an administrator (you can use `+` as your address to represent localhost): ```powershell netsh http add urlacl http://your-address:PORT/ user=USERNAME ``` * WCF requires a getter AND setter for all properties (you can make them protected though): * otherwise the service host answers the SOAP request with a RST packet, resulting in a error saying: `[HTTP] Error Fetching http headers` * To trace WCF events: <a href="" target="_blank">See MSDN</a> * EntityFramework (EF) can be installed in the NuGet packet manager and will be automatically installed when running your project on a different machine * Unfortunately, EntityFramework does not yet support an InMemory database for testing in the current stable version (EF6) * However, it will be supported in EF7