[英]How do I return a string from WCF Workflow (WF4) when invoked by a Interface with ChannelFactory?
如果我托管(WF4 + WCF)並在IIS中運行的工作流,則實現以下接口:
[ServiceContract]
public interface IMessageService
{
[OperationContract]
string SendMessage(string message);
}
(使用System.ServiceModel.Activities
RecieveActivity
和SendReply
)
並像這樣調用它:
var channel = new ChannelFactory<IMessageService>().CreateChannel(<init params>);
string answer = channel.SendMessage("Testmessage");
那么answer
始終為空。 如果我通過WcfTestClient使用工作流,則可以看到有一個返回的xml對象。
如何使工作流返回字符串以填充
answer
?
(我想避免“添加ServiceReference並返回很多xml方法”)
您需要一個[return]
屬性來指定如何查找結果。
在SendReplyToReceive
您可以選擇發回Message
或Parameters
。 以我的經驗,您需要選擇“ Parameters
但只返回一個。 假設您給return參數指定名稱“ result”,那么您在接口協定上需要此屬性:
[return: MessageParameter(Name = "result")]
這是我的一個完整例子。
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);
}
}
順便說一句,在您的示例中,我不確定未指定OperationContract會怎樣,但是您確實很滿意-它們確實很痛苦,因為您必須在合同和工作流中指定的格式不同 。
另外,萬一你不知道,它可能會導致一些非常微妙的錯誤:你傳遞的名字被認可的參數,所以它是imprtant這個名字你指定在接口的入站的參數是相同的工作流程。 當您考慮時很明顯,但是可以吸引您。 哦,請避免使用太長的方法名稱,因為它們會因誤導性錯誤消息而中斷。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.