C# 将自定义对象传递给Windows工作流WCF服务
由于某种原因,我在传递对象时遇到问题,我不知道为什么。我得到的对象引用未设置为对象错误的实例 基本上,我从我的客户端应用程序调用Windows Work 客户端代码C# 将自定义对象传递给Windows工作流WCF服务,c#,wcf,workflow-foundation,C#,Wcf,Workflow Foundation,由于某种原因,我在传递对象时遇到问题,我不知道为什么。我得到的对象引用未设置为对象错误的实例 基本上,我从我的客户端应用程序调用Windows Work 客户端代码 Workflow1Client client = new Workflow1Client(); ACME.Order newOrder = new ACME.Order(); newOrder.Property1 = "xyz"; //set all the other properties string status = cl
Workflow1Client client = new Workflow1Client();
ACME.Order newOrder = new ACME.Order();
newOrder.Property1 = "xyz";
//set all the other properties
string status = client.GetData(newOrder);
//**This is where object reference error occurs**
[ServiceContract]
public interface IWorkflow1
{
[OperationContract]
string GetData(ACME.Order NewOrder);
// TODO: Add your service operations here
}
代理期望值
public string GetData(ACME.Order NewOrder)
{
return base.Channel.GetData(NewOrder);
}
工作流代码
Workflow1Client client = new Workflow1Client();
ACME.Order newOrder = new ACME.Order();
newOrder.Property1 = "xyz";
//set all the other properties
string status = client.GetData(newOrder);
//**This is where object reference error occurs**
[ServiceContract]
public interface IWorkflow1
{
[OperationContract]
string GetData(ACME.Order NewOrder);
// TODO: Add your service operations here
}
我非常感谢你在这方面的帮助。除此之外,还有发送对象(ACME.Order)的良好实践,还是我应该尝试以不同的方式解决这个问题
谢谢我自己也遇到过这种情况,在我的情况下,这是自定义对象上的序列化错误。为了能够跨WCF发送自定义对象,它应该具有[Serializable]属性。要进行测试,请查看是否可以将对象序列化为XML文件。如果失败,WCF传输将不起作用
希望这能有所帮助。谢谢Jerb,我能让它正常工作。它与我的工作流上的ServiceOperationInfo相关。您还可以在数据类上使用[DataContract]属性,还可以将[DataMember]属性附加到要包含在序列化中的数据类的属性。这为序列化的内容提供了更细粒度的控制。