I have a singleton WCF service that owns sockets that are used to communicate with an external party. I am using .NET 3.5 SP1
The code is thread safe and scales well.
When I run this code in a WCF service hosted in IIS 7.5 on Windows 2008 R2 64 bit, the WCF service cannot accept more than one concurrent call.
My service class implements three interfaces, each with a standard ServiceContract attribute and only a namespace, no other settings
I have the following attribute on the class:
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single,
ConcurrencyMode = ConcurrencyMode.Multiple)]
I have the following behavior configuration:
<behavior name="MyServiceAsyncBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceThrottling maxConcurrentCalls="60" maxConcurrentSessions="60"
maxConcurrentInstances="60" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
I created a seperate application, used the exact same configuration file (literally a copy, no changes were made to it), and a singleton service class with the exact same ServiceBehavior attribute on the class. This service DOES NOT exhibit the same behavior, it happily allows concurrent calls.
The only differences between the test service that allows concurrent calls and the real service that does not is that the real service owns worker threads and TCP sockets, and implements three interfaces instead of one.
What am I missing here?
I found the issue. It relates to the remote TCP service. I was using an ill-behaved test service, which never returned to the caller.
WCF seems to have prevented concurrent calls to the singleton because the singleton was locked in a tight loop
Related
I have a Windows service that listens on a queue; when there is a new message, it parses it, and stores it in its own storage.
It's "uni-directional" in the sense that it just listens on a queue, but doesn't expose any endpoint and it doesn't interact with other services.
Is this considered a micro-service?
As the name implies any service which is not monolithic, which can be independently built and deployable can be a microservice.
There is 12 factor approach to be called a true micro service, https://www.nginx.com/blog/microservices-reference-architecture-nginx-twelve-factor-app/
Microsoft have a article about that.
https://learn.microsoft.com/en-us/azure/architecture/guide/architecture-styles/microservices
Services communicate with each other by using well-defined APIs.
Internal implementation details of each service are hidden from other
services.
We run a number of ASP.NET MVC sites - one site per client instance with about 50 on a server. Each site has its own configuration/database/etc.
Each site might be running on a slightly different version of our application depending on where they are in our maintenance schedule.
At the moment for background processing we are using Quartz.net which runs in the app domain of the website. This works well mostly but obviously suffers issues like it isn't running when the appdomain shuts down such as after prolonged activity.
What are our options for creating a more robust solution?
Windows Services are being discussed but I don't know how we can achieve the same multi-site on different versions we get within IIS.
I really want each IIS site to have its own background processing which always runs like a service but is isolated in the same way an IIS site is.
You could install a windows service for each client. That seems like a maintenance headache though.
You could also write a single service that understands all versions of your app, then processes each client one after the other.
You could also create sql server jobs to do this, and setup one job for each customer.
I assume that you have multiple databases for each client as you mentioned.
Create a custom config file with db connection-strings for each client.
e.g.
<?xml version="1.0" encoding="utf-8" ?>
<MyClients>
<MyClient name="Cleint1">
<Connection key="Client1" value="data source=<database>;initial catalog=client1DB;persist security info=True;user id=xxxx;password=xxxx;MultipleActiveResultSets=True;App=EntityFramework" />
</MyClient>
<Myclient name="client2".....></MyClient>
</MyClients>
Write a windows service which loads the above config file (clients|connectiostring) into the memory and iterate through each client database config. I guess all clients have similar job queuing infrastructure, so that you can execute same logic against each database.
You can use a Mutex to initiate the windows service for a client so that it will make sure two instances of the service for the same client won't run at the same time.
apologies in advance for this question being dumb, or previously covered. I have researched far and wide but have not found any resources on WCF/ Windows Services that cover this question.
I have a managed Windows Service which is working nicely. Every n (>5) seconds it checks on the status (e.g. memory consumption) of some processes and other Windows services and also does some database logging and raises events where necessary.
I intend to make an ASP.NET website that would allow users to query the status of the processes that the Windows Service is monitoring. Having researched the options it looks like the up-to-date method would be to use a WCF Service, hosted in the Windows Service, to act as intermediary between the ASP.NET website and the Windows Service. Such that, a user could request through the browser a snapshot of the current status of whatever set of processes the Windows Service was monitoring, and have this request and subsequent response relayed through the WCF service (using named pipes, I think).
So, my difficulty is that there a set of methods and events in the Windows Service for which a single root object exists (let's say MonitorObject). I don't see how the ServiceHost can be instantiated with the reference to MonitorObject so that the WCF Service can call the methods in the Windows Service. I am thinking that perhaps I need to make the Monitor object a shared (I am VB'ing) member of the Windows Service class (that contains OnStart and OnStop) and make all the events shared so that the WCF Service can just access the WindowsService.SharedMonitorObject without needing to be passed the object....
However, I am lost in the subject and am seeking any advice on how best to proceed.
Thanks in advance.
I think you're going down the right track. I wouldn't necessarily make the entire MonitorObject shared, but you might put a shared method in that object that will return the single root object to the caller.
There is a design pattern called the Singleton Pattern that will help you with this. Jon Skeet has written an excellent article on some of the things to be aware of when using this pattern in .NET. His article uses C# for the examples, but here's a SO question referencing this pattern using VB.
While it's unclear from your description, my guess is that your Windows Service is essentially single-threaded right now. Just keep in mind that once you add the WCF service, you'll need to make the methods that it references thread-safe.
I have a L2S Repository class which instantiates the L2S DataContext in its constructor.
The repository is instantiated at run time (using Unity) in a service hosted in IIS with WCF.
When I run up the client MVC applicaton the calls to the backend WCF service work for a while and then timeout.
I suspected perhaps a database issue as I was depending on IIS garbage collection to dispose of unused DataContext instances in the IIS host but when I checked the characteristics of the problem I notice the following:
The client makes the call to WCF but the WCF service does not respond.
Next, the client times out
Some time later (several minutes) the service actually executes the request by instantiating the repository and servicing the call.
I have checked both client and server traces logs and only the client shows WCF errors (the timeout error).
Where should I look? Is it something in WCF or is L2S possibly blocking with unfreed conenctions, resources etc.?
Many thanks
Brian
Did not close the connection on the Client side! Dohhh!
i have a rails app must consume wcf services provided by asp.net, are there any ruby clients for wcf?
Are you in control of the web service? Can you change the web.config a bit? (You indicate Asp.Net so I guess that means the WCF Service is hosted in IIS.)
A WCF service can be exposed as a regular old web-service. It's one of the promises of WCF: the same service can be exposed via many bindings with nothing but a configuration change.
<endpoint address="" binding="basicHttpBinding" contract="IServiceContract">
Then you can call it from Ruby like so:
require 'soap/wsdlDriver'
soap = SOAP::WSDLDriverFactory.new("http://host/SomeService.svc?wsdl").create_rpc_driver
soap.ServiceMethod(:param1=> Value, :param2 => AnotherValue)