Sometimes adding a WCF Service Reference generates an empty reference.cs

Generally I find that it’s a code-gen issue and most of the time it’s because I’ve got a type name conflict it couldn’t resolve. If you right-click on your service reference and click configure and uncheck “Reuse Types in Referenced Assemblies” it’ll likely resolve the issue. If you were using some aspect of this feature, … Read more

WCF ServiceHost access rights

The issue is that the URL is being blocked from being created by Windows. Steps to fix: Run command prompt as an administrator. Add the URL to the ACL netsh http add urlacl url=http://+:8000/ServiceModelSamples/Service user=mylocaluser

How to add a custom HTTP header to every WCF call?

The advantage to this is that it is applied to every call. Create a class that implements IClientMessageInspector. In the BeforeSendRequest method, add your custom header to the outgoing message. It might look something like this: public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel) { HttpRequestMessageProperty httpRequestMessage; object httpRequestMessageObject; if (request.Properties.TryGetValue(HttpRequestMessageProperty.Name, out httpRequestMessageObject)) { httpRequestMessage = … Read more

Turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server

Define a behavior in your .config file: <configuration> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name=”debug”> <serviceDebug includeExceptionDetailInFaults=”true” /> </behavior> </serviceBehaviors> </behaviors> … </system.serviceModel> </configuration> Then apply the behavior to your service along these lines: <configuration> <system.serviceModel> … <services> <service name=”MyServiceName” behaviorConfiguration=”debug” /> </services> </system.serviceModel> </configuration> You can also set it programmatically. See this question.

Catch-22 prevents streamed TCP WCF service securable by WIF; ruining my Christmas, mental health

WCF has gotchas in a few areas with streaming (I’m looking at you, MTOM1) due to a fundamental issue in how it fails to perform preauthentication the way most people would think that should work (it only affects subsequent requests for that channel, not the first request) Ok, so this is not exactly your issue … Read more

The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication

You get this error because you let a .NET exception happen on your server side, and you didn’t catch and handle it, and didn’t convert it to a SOAP fault, either. Now since the server side “bombed” out, the WCF runtime has “faulted” the channel – e.g. the communication link between the client and the … Read more

WCF service startup error “This collection already contains an address with scheme http”

In .Net 4, you can use the multipleSiteBindingsEnabled option: <system.serviceModel> <serviceHostingEnvironment multipleSiteBindingsEnabled=”true”> </serviceHostingEnvironment> </system.serviceModel> Then, you won’t have to specify each address. http://msdn.microsoft.com/en-us/library/system.servicemodel.servicehostingenvironment.multiplesitebindingsenabled.aspx

When to use DataContract and DataMember attributes?

Since a lot of programmers were overwhelmed with the [DataContract] and [DataMember] attributes, with .NET 3.5 SP1, Microsoft made the data contract serializer handle all classes – even without any of those attributes – much like the old XML serializer. So as of .NET 3.5 SP1, you don’t have to add data contract or data … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)