How do I pass values to the constructor on my wcf service?

You’ll need to implement a combination of custom ServiceHostFactory, ServiceHost and IInstanceProvider. Given a service with this constructor signature: public MyService(IDependency dep) Here’s an example that can spin up MyService: public class MyServiceHostFactory : ServiceHostFactory { private readonly IDependency dep; public MyServiceHostFactory() { this.dep = new MyClass(); } protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) … Read more

How to use Fiddler to monitor WCF service

You need to add this in your web.config <system.net> <defaultProxy> <proxy bypassonlocal=”False” usesystemdefault=”True” proxyaddress=”http://127.0.0.1:8888″ /> </defaultProxy> </system.net> then Start Fiddler on the WEBSERVER machine. Click Tools | Fiddler Options => Connections => adjust the port as 8888.(allow remote if you need that) Ok, then from file menu, capture the traffic. That’s all, but don’t forget … Read more

Web Service vs WCF Service

This answer is based on an article that no longer exists: Summary of article: “Basically, WCF is a service layer that allows you to build applications that can communicate using a variety of communication mechanisms. With it, you can communicate using Peer to Peer, Named Pipes, Web Services and so on. You can’t compare them … Read more

MemoryCache Thread Safety, Is Locking Necessary?

The default MS-provided MemoryCache is entirely thread safe. Any custom implementation that derives from MemoryCache may not be thread safe. If you’re using plain MemoryCache out of the box, it is thread safe. Browse the source code of my open source distributed caching solution to see how I use it (MemCache.cs): https://github.com/haneytron/dache/blob/master/Dache.CacheHost/Storage/MemCache.cs

CORS – How do ‘preflight’ an httprequest?

During the preflight request, you should see the following two headers: Access-Control-Request-Method and Access-Control-Request-Headers. These request headers are asking the server for permissions to make the actual request. Your preflight response needs to acknowledge these headers in order for the actual request to work. For example, suppose the browser makes a request with the following … Read more

Decompressing GZip Stream from HTTPClient Response

Just instantiate HttpClient like this: HttpClientHandler handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }; using (var client = new HttpClient(handler)) //see update below { // your code } Update June 19, 2020: It’s not recommended to use httpclient in a ‘using’ block as it might cause port exhaustion. private static HttpClient client … Read more

Can we create custom HTTP Status codes?

Yes, as long as you respect the class — that is, 2xx for success, 4xx for Client error, etc. So you can return custom 4XX error codes (preferably those that are unassigned) for your own application’s error conditions. To quote from [RFC 2616][1]: “HTTP status codes are extensible. HTTP applications are not required to understand … Read more

What is the difference between a WCF Service Application and a WCF Service Library?

A service application includes a website host already setup for you. A service library is a library of services that a host can reference and startup. If you start with a service library (recommended) you can then choose any host you wish (a windows service, IIS/ASP.NET, or even a console application) and you’d just reference … Read more

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