Best practice for large WCF service?

That’s been a big question surrounding services since their inception. SOA done successfully is SOA planned to the extent you’re talking about. Having said that, I’ve always leaned more toward splitting services out, but using them in a composite manner. That is, several endpoints when you have several contracts, but most of them are only … Read more

Async WCF client calls with custom headers: This OperationContextScope is being disposed out of order

According to Microsoft documentation: Do not use the asynchronous “await” pattern within a OperationContextScope block. When the continuation occurs, it may run on a different thread and OperationContextScope is thread specific. If you need to call “await” for an async call, use it outside of the OperationContextScope block. So the simplest proper solution is: Task<ResponseType> … Read more

Error: Cannot obtain Metadata from WCF service

You need a metadata endpoint for your service, here`s an example. <services> <service name=”MyService” behaviorConfiguration=”MEX”> <endpoint address=”http://localhost:8000/MEX” binding=”mexHttpBinding” contract=”IMetadataExchange” /> </service> </services> <behaviors> <serviceBehaviors> <behavior name=”MEX”> <serviceMetadata/> </behavior> </serviceBehaviors> </behaviors>

How can I configure WCF to use x509 certificates over the internet?

The following steps are a guide to get you started: 1) Firstly, you need a Root Authority to generate your client and server certificates. You can either use an external Authority Provider (e.g. Verisign) or you can generate your own using something like Microsoft Certificate Server. To generate a development Root Authority certificate you can … Read more

WCF: What is a ServiceHost?

A ServiceHost basically provides you everything you need to host a WCF service in a non-IIS or WAS setting. A common place for a ServiceHost would be in a console app or Windows service. See the example code from MSDN for how to setup a ServiceHost in a console app.

OperationContext.Current is null after first await when using async/await in WCF service

It is unfortunate that this doesn’t work and we will see about getting a fix out in a future release. In the mean time, there is a way to reapply the context to the current thread so that you don’t have to pass the object around: public async Task<double> Add(double n1, double n2) { OperationContext … Read more

WCF – Inspect the messages being sent/received?

To view the message contents you must add a source for System.ServiceModel.MessageLogging in your configuration file. The message tab in the Trace Viewer will show the full message for a particular service call. Here is a sample configuration file: <configuration> … <system.diagnostics> <sources> <source name=”System.ServiceModel” switchValue=”All” propagateActivity=”true”> <listeners> <add name=”traceListener” /> </listeners> </source> <source name=”System.ServiceModel.MessageLogging” … Read more