If I have a workflow hosted (WF4 + WCF) and running in IIS implementing the following interface:
[ServiceContract]
public interface IMessageService
{
[OperationContract]
string SendMessage(string message);
}
(Using RecieveActivity and SendReply from System.ServiceModel.Activities)
And invoke it like this:
var channel = new ChannelFactory<IMessageService>().CreateChannel(<init params>);
string answer = channel.SendMessage("Testmessage");
Then answer is always null. If I consume the workflow through the WcfTestClient I can see there is an returned xml object.
How can I make the workflow return a string to populate
answer?
(I’d like to avoid the “Add a ServiceReference and return a lot of xml-approach”)
You need a
[return]attribute to specify how to find the result.In the
SendReplyToReceiveyou can choose between sending back aMessageorParameters. In my experience, you need to chooseParametersbut only send back one. Assuming you give the return parameter the name “result” then you need this attribute on your interface contract:Here is a full example of one of mine;
Incidentally, in your example I am not sure how you are getting away with not specifying the OperationContract but great that you are – they are a real pain because the format you have to specify them in is different in the contract and in the workflow.
Also, just in case you don’t know and it can cause some really subtle bugs: The parameters you pass in are recognised by name, so it is imprtant that the name you specify for inbound parameters in your interface is the same as in your workflow. Obvious when you think about it but can catch you out.
Oh, and avoid method names that are too long as they will break as well with misleading error messages.