c# - How do I return a string from WCF Workflow (WF4) when invoked by a Interface with ChannelFactory? -


if have workflow hosted (wf4 + wcf) , running in iis implementing following interface:

[servicecontract] public interface imessageservice {         [operationcontract]      string sendmessage(string message); } 

(using recieveactivity , sendreply system.servicemodel.activities)

and invoke this:

    var channel = new channelfactory<imessageservice>().createchannel(<init params>);     string answer = channel.sendmessage("testmessage"); 

then answer null. if consume workflow through wcftestclient can see there returned xml object.

how can make workflow return string populate answer?

(i'd avoid "add servicereference , return lot of xml-approach")

you need [return] attribute specify how find result.

in sendreplytoreceive can choose between sending message or parameters. in experience, need choose parameters send one. assuming give return parameter name "result" need attribute on interface contract:

[return: messageparameter(name = "result")] 

here full example of 1 of mine;

namespace neworbit.exverifier.model.workflow.case {     using system;     using system.servicemodel;      using neworbit.exverifier.model.workflow;      [servicecontract(namespace = "urn://exverifier.neworbit.co.uk/")]     public interface icaseworkflow     {         [operationcontract(action = "urn://exverifier.neworbit.co.uk/neworbit.exverifier.model.workflow.case.icaseworkflow/start",             replyaction = "urn://exverifier.neworbit.co.uk/neworbit.exverifier.model.workflow.case.icaseworkflow/startreply")]         [return: messageparameter(name = "result")]         workflowinstanceidentifier start(int caseid);          [operationcontract(action = "urn://exverifier.neworbit.co.uk/neworbit.exverifier.model.workflow.case.icaseworkflow/applicationstatechanged",             replyaction = "urn://exverifier.neworbit.co.uk/neworbit.exverifier.model.workflow.case.icaseworkflow/applicationstatechangedreply")]         [return: messageparameter(name = "result")]         bool applicationstatechanged(guid instanceid, int applicationid);          [operationcontract(action = "urn://exverifier.neworbit.co.uk/neworbit.exverifier.model.workflow.case.icaseworkflow/cancel",             replyaction = "urn://exverifier.neworbit.co.uk/neworbit.exverifier.model.workflow.case.icaseworkflow/cancelreply")]         [return: messageparameter(name = "result")]         bool cancel(guid instanceid);     } } 

incidentally, in example not sure how getting away not specifying operationcontract great - real pain because format have specify them in different in contract , in workflow.

also, in case don't know , can cause subtle bugs: parameters pass in recognised name, imprtant name specify inbound parameters in interface same in workflow. obvious when think can catch out. oh, , avoid method names long break misleading error messages.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -