Multiple calls to service not handling all requests - wcf

I have a Silverlight app that uses WCF for communication with my SQL Server via Entity Framework. When I send multiple requests to the service it fails to send all. If I use the Callback event and send each request as the previous one completes all is well. How can I get this to work without this workaround?
Edited:
For i As Integer = 0 To someNumberOfTimesInLoop
serv.CloseElement_IncAsync(Params...)
Next
So I wonder if it's a concurrency problem as they hit at the same time and the Id fields for these tables are not incremented in time?
I have added this code in my App.xaml.vb based on this blog:
WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp)
Any ideas?

Related

Best way to queue WCF requests so that only one is processed at a time

I'm building a WCF service to handle all QuickBooks SDK functionality for two companies. Since the QuickBooks SDK needs to open/close the actual QuickBooks application to process a request, only one can be handled at a time or QuickBooks goes into a really bad state. I'm looking for the best way to allow end users to make a QuickBooks data request, and have my WCF application hold that request until the previous request is completed.
If nothing is currently being processed, then the request will go through immediately.
Does anyone know of the best method to handle that type of functionality? Anything third party/built-in .NET libraries?
Thanks!
Use WCF Throttling. Its configurable and will solve your problem without code changes.
See my answer for WCF ConcurrencyMode Single and InstanceContextMode PerCall.
One way to do this is to Place a Queue between the user and the Quickbooks Application:
The request from the user is placed i a Queue or Data table.
A background process reads the one item at a time out of the Queue, sends it to Quickbooks and Places the result in a result table.
The Client applictaion reads the result from the result table.
This requires some work, but the user will allways be able to submit requests and only one will be processed at a time.
The solution given by ErnieL will also work if you use Concurrency mode Single, but in Heavy load scenarios the users will get timeouts.

Can a WCF Service be used the same way a socket connection is used?

I currently have a windows application that contains a chart control. The app connects to a socket (TCP/IP) on a server.
On connect, the server sends out 100 records through a byte stream.
On receive, the application deciphers the byte stream into a data table.
The application then plots various records from that table into the chart control.
The application asynchronously listens on the connection for more information.
The server, as it collects data through various services, will send out just one record at a time as it gets updates.
The application receives these updates, deciphers them, updates the data table and updates the chart control.
My question:
We would like to make the Windows application into a Web application. We would like to develop a WCF service on the server to update the web page in real time (as it does now in the windows app), but using XML.
I have not used WCF before, and as I have been researching, it seems to me that the client would have to initiate the update at timed intervals. That the WCF service wouldn't be able to contact the client when it receives an updated record. Is this correct, or have I missed something? Any suggestions you can offer would be greatly appreciated.
You should be able to do this using a duplex service and callbacks, this article details it a bit.

Alternative to wcf callback.Is there one?

Wondering if there is a better option than a wcf callback.
When processing some data Invoices and printing them and I need to constantly show the user in a winform -"Invoice 1 Printed" invoice 2 printed etc....
I have put together a call back mechanism and all works but wondering if there is a better way of doing this .
Was thinking along the line if 2 services would be better than a callback.
One that loops at server side through the invoices and saves to the database the status ="Printed" and the other the queries it and check if it has printed and return to the user
.
Would that be better than a callback,faster and avoid timeouts etc..?
Just thinking as an alternative as a collegue who used callback extensively said" dont use callback use 2 services".
What would you do if you had to process 2000 invoices and notify the user for each one
Any suggestions?
On one project we have done the following:
All windows clients also host a WCF service
When the windows client starts it registers itself with the server, that this user is loggon with this IP address.
The server stores info on who is logged in where
Then we can send a message to the user whenever we want
When the client recieves the message we fire an event, then whatever part of the UI that is affected can update itself or show a message.

Implement long-polling API with Symfony

I am trying to implement an API which uses the long-polling concept in Symfony framework.
Let's say that I have a table 'feeds' which can only grow (assume that users can insert thier feed from other interface).
I want to create a client-side real-time updated page. The idea is the following:
Client send an ajax request with timestamp of last modification (first time sends 0)
Server compares timestamp of client to timestamp, to retrieve all messages with bigger timestamp than the one sent by user
If there are newer messages, return them immediately to the client, with the timestamp of the latest one
On other hand, if there are no new messages, enter into a 2 minutes busy-wait loop, checking every 1-3 seconds (randomly) whether there are new messages.
When client receive servers answer, browser updates view and immediately sends a new ajax request.
In other words, instead of send an AJAX call every x seconds, the server holds the request till it has new information for us.
Having good experience with Symfony I tried to implement a simple demo of this api, and it works great. I had a problem of session blocking (the ajax call is held so access to the server is not possible), so I simply added the following to the action:
public function executeIndex(sfWebRequest $request)
{
session_write_close();
:
:
(see also this link)
Then I testes massive access to the API. 100 users works fine, 1000 everything crashes.
I realized that I have two problems:
For each access a new DB connection is opened
For each access the server executes a new process
For the first problem I tried to put persistent: true In my database.yml Doctrine connetor. When I monitored the server connections I saw that still each access to the API opens a new connection. So basically I am still blocked with the same two problems.
Does anyone have any idea or experience with this issue?? Or maybe I should give-up the idea of implementing my api with Symfony??
I think using symfony for this, is the wrong approach. Using Sockets would be much easier.
For example have a look at nodejs or ape-project (comet)
they both are able to handle much more current users than apache, lighttpd or nginx...
Apache creating different threads for each user and each thread have a separate database connection. that's why the db connection are high

WCF Service- Sending back object to calling App

My WCF service(hosted as Windows Service), has some 'SendEmail' methods, which sends out emails after doing some processing.
Now, I have got another requirement where client wants to preview emails before they are being sent out, so my WCF service needs to return whole email object to calling web app.
If client is happy with emails object, they can simply click 'Send out' which will then again call WCF service to send the emails.
Because at times it can take a bit longer for emails object processingy, I do not want calling application to wait until emails object is ready.
Can anyone please guide what changes I need to make to my WCF service (which currently has all one way operation)?
Also, please guide me whether I need to go for Asynch operation or message queuing or may be a duplex contract?
Thank you!
Based on your description I think you will have to:
Change current operation from sending email to storing email (probably in database).
Add additional operation for retrieving prepared emails for current user
Add additional method to confirm sending one or more emails and removing them from storage.
The process will be:
User will trigger some http request which will result in calling your WCF service for processing (first operation)
WCF service will initiate some processing (asynchronously or firt operation will be one-way so that client doesn't have to wait).
Processing will save email somehow
Depend on duration of processing you can either use AJAX to poll WebApp which will in turn poll WCF service for prepared emails or you will create separate page which will user have to access to see prepared emails. Both methods are using second operation.
User will check prepared email(s) and trigger http request which will result in calling third operation to send those emails.
You have multiple options:
Use Ladislav's approach. Only to add that service returns a token and then client uses the token to poll until a time out or a successful response. Also server keeps these temp emails for a while and after a timeout purges them.
Use duplex communication so that server also gets a way to callback the client and does so when it has finished processing. But don't do this - and here is my view why not.
Use an Asynchronous approach. You can find nice info here.