WCF Workflow Service single instance correlation - wcf

Using visual studio 2010 RC/.Net 4.0
I have a wcf workflow service with three receive activities defined, basically StartProcessing, StopProcessing, and GetProcessingStatus. This is a long running service that continues to poll an external service for data once StartProcessing is called, until StopProcessing is called.
My problem is with figuring out how to use correlation to ensure that all calls into the service call the same instance of the workflow. I am trying to avoid requiring any sort of instance id be required to be passed back in to subsequent calls to the service. In a nutshell, I would like the workflow being executed to be a singleton, and ensure that all receive activities operate on the same instance. How do I go about doing this?

You can correlate on a constant for example. Edit the XPath in query correlation to return the number 1 for example.

I think that what you want is impossible, you need to correlate, WWF does not know how to execute it. If two parallel calls are received they will use the same object with unexpected results.
In wcf it could be possible, you can set a session in the client or you could manage wcf object creation, but in WWF I think you even don't have that options.

Related

Why do I have to reverse the parameters when calling a WCF service?

I have a WCF Service with a method that has 3 parameters: 1 input and 2 outputs. Eg.
Foo(input, out1, out2)
I add the service reference fine in my client code, however, when I go to call the service, visual studio doesn't recognise the parameters properly. I have to call the service as
Foo(out1, out2, input)
Why is this? I can see that the order is reversed in the reference file of the service reference, but if I change the order then visual studio gives me errors saying that they are not in the right order. Is this normal behaviour? Do I just need to call the service using the reversed parameters?
...when I go to call the service, visual studio doesn't recognise the
parameters properly
The problem you are having is by design.
When the service exposes the WSDL metadata to consumers, there is nowhere in the service definition where the service operation signature is maintained in its original form.
Instead, the input and output parameters are declared in separate collections.
Now, it's the job of the Add Service Reference tooling to make an attempt at reconstructing the original operation signature for consumers from the metadata, but in this instance it cannot. The original operation signature has been lost at this point. So it just reconstructs the operation processing the output parameters collection first, and then the input parameters, hence your observed behaviour.
The only way to make this go away is to:
not use output parameters in your service operation definition. This is recommended anyway, as output parameters are a code quality flag and should be avoided if possible, or
not expose metadata from the service. Consumers can call the service directly by using the actual service definition types using a WCF channel instead of using a service reference. This is generally regarded as being a superior method for calling a service in WCF.
Or you could just do nothing. The consumer is still able to call the service operation right?

How do we initialize objects in Workflow (i.e. .xamlx)

My WCF service is suppose to push a call to MSMQ (queue), which eventually will call another WCF service to perform database operations.
I have created a new project for MSMQ operations, and it has an "xamlx" file for the workflow. How do (or in which event) I initialize objects so that they can be accessible in the destination WCF?
hugh makes a great point. Based on what you've told us, it doesn't seem that workflow is absolutely necessary here.
If it is needed for some other reason (e.g. flowing a distributed transaction), then in your workflow project, you should be able to do Add Service Reference to your destination WCF service. This will generate you activities that match the signature of your destination WCF service. The objects that those activities expect can be initialized via expressions, e.g. directly on the activity in the expression text box, or using a variable that is set via an Assign activity.
Hope that helps,
-- Dave, WF Team

Long calculation in a wcf restful service

I have a WCF restful service and it works correctly, the problem is that the service expose a method "Calculate" and it may take several minutes to complete the calculation, and since REST is a stateless method, I'm running out of ideas !
should I maintain the session ?
how can I do a callback ?
10 minutes waiting for a response in a website is not convenient, but I have to find a solution.
PS: the service MUST be restful, and I cant reduce the calculation time.
I asked about your clients because if they were .Net only, you could implement the async programming model, but since they aren't...
You can do something like in this post - WCF Rest Asynchronous Calling Methods
Basically your method will spawn an additional thread to do the actual calculation work, and return some sort of token to the calling client immediately in the main thread. The client can then use this token in a polling method to check if the calculation is complete.
You can create a one-way WebMethod to submit the intial calculation request. Inside your calculation code, you need to update a database table or similiar with progress, either percentage or completion.
You will then need to create an additional 'Polling' method that you can use to check the status, using the previous table.
When your calculation method marks it as complete, you can then call a final 'GetResults' method which will do just that.
We do something similiar for large file imports that are submitted via web services and it works very well.
Some info;
http://msdn.microsoft.com/en-us/library/system.web.services.protocols.soapdocumentmethodattribute.oneway(v=vs.71).aspx

Design for a special WCF service

I need to implement a WCF service which in turn calls a third party web service for some XML result.The client calls come from windows WF apps & will be on separate processes.But for client calls coming from the same parentID, there should be only one call per ParentID, i will explain,
MainID1\SubID1 & MainID1\SubID1 on different processes calls the WCF service for result & if MainID1\SubID1 was the first to make the call, MainID1\SubID2 should wait until the first call is completed.The idea is to prevent unnecessary call to the third party web service, if we get the expected results already from the first call.
But if there are MainID2\SubID1,MainID2\SubID2,MainID2\SubID3 calls, that should be served by a different instance of the WCF service.
In short:
Related requests should be processed sequentially by one instance of WCF service
Unrelated requests should be processed by separate instance
Sorry, if haven't made myself clear, not at the liberty to use the actual business terms(which might have helped to define related & unrelated clients better).
Is this really possible?
Yes, you can do this, but it will not be trivial. Basically you need another component between your WCF Web Service and the 3rd Party service which handles the throttling/locking behavior which you describe. That component needs to create a object for each unique combination and then use that as a lock guard around the outbound call.
Realize that this is clearly multi-threaded development, making it hard to test, and prone to errors if you're not experienced with the ideas around it. You'll want to ensure you're doing double-checked locking whenever you take out a lock.

Action vs Reply action WCF

What's the use of action/reply action for service operation in WCF. So far, what I've understood is; action is used by WSDL to identify the service operation to which the message from the client belongs and in return reply action is used by service operation to identify the caller to which reply message belong --> Please correct me if I am wrong with this!
Now, I want to understand; what's the real use (apart from handling anonymous messages by using aster ix [*]), I mean this could well be handled internally by WCF instead of exposing it to the developer.
Also, why is action and replyaction required at all? I mean, we already have a name property for the service operation to identify the method and when I call Proxy.SomeMethod() then somemethod is already mapped to the Name property and it should be enough to identify the destination method for the message and similarly the replyaction. Please clarify.
Can I please get a simple real world scenario/or link to that to understand Action/ReplyAction in real life.
Many Thanks.
Actions are part of the various SOAP and WS-* specifcations.
So the first point is that this is not something unique to WCF it is a standard part of the specification you need to support if you want to have interoperable web services. They are used for message routing and other message handling functions.
Second, WCF DOES manage these by default. You only need to specify them yourself if you wish to customise or manage them in some other way. E.g. WCF will automatically generate them into the WSDL for you. WCF will also use them by default when it is selecting which operation to invoke for an incoming message. Again, WCF provides extension points to customise this behavior if you require.