本文介绍了如何将XmlDocument转换为XLANGMessage类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! 如何将XmlDocument转换为XLANGMessage类型? 我试过下面的方法,下面两个方法抛出错误:不能隐式转换XmlDocument为XLangMessage ... 任何其他想法,请分享。 TRY1 - public XLANGMessage convertToXlandMsgFromXml(XmlDocument tempInput) { XLANGMessage sampleOutput; tempInput.Load(@InputMessage.xml); XLANGMessage sampleOutput = tempInput; } TRY2- public class FileStreamFactory:IStreamFactory { string _fname; public FileStreamFactory(string fname) { _fname = fname; } public Stream CreateStream() { return new FileStream ( _fname, FileMode.Open, FileAccess.Read, FileShare.Read ) } } public static void AssignStreamFactoryToPart(XLANGMessage msg) { IStreamFactory sf = new FileStreamFactory(@c:\\data .xml); msg [0] .LoadFrom(sf); } } 解决方案应检查此链接(最后一部分): http://blogs.msdn.com/b/paolos/archive/2009/09/10/4-different- 创建一个自定义类型的方法来创建一个自定义类型例如CustomBTXMessage [Serializable] public sealed class CustomBTXMessage:BTXMessage { public CustomBTXMessage string messageName,Context context):base(messageName,context) { context.RefMessage(this); } } 然后您可以 - 从该类型创建一个对象,将你的xml加载到身体部分。 var customBTXMessage = new CustomBTXMessage(XLANGMessage,Service.RootService.XlangStore.OwningContext); customBTXMessage.AddPart(string.Empty,Body); 我将以流的形式加载xml文档,而不是从流中加载body部分 customBTXMessage [0] .LoadFrom(stream); 这部分代码将返回一个XLANGMessage var responseMessage = customBTXMessage.GetMessageWrapperForUserCode(); 祝你好运。 Jonathan How can I convert a XmlDocument to a XLANGMessage type?I have tried with below method,Below two methods throws error : "Cannot Implicitly convert XmlDocument to XLangMessage...Any other thoughts, please share.TRY1--public XLANGMessage convertToXlandMsgFromXml(XmlDocument tempInput){ XLANGMessage sampleOutput; tempInput.Load(@"InputMessage.xml"); XLANGMessage sampleOutput = tempInput;}TRY2-- public class FileStreamFactory : IStreamFactory{ string _fname; public FileStreamFactory(string fname) { _fname = fname; } public Stream CreateStream() { return new FileStream ( _fname, FileMode.Open, FileAccess.Read, FileShare.Read ); } } public static void AssignStreamFactoryToPart(XLANGMessage msg) { IStreamFactory sf = new FileStreamFactory( @"c:\\data.xml" ); msg[0].LoadFrom( sf ); }} 解决方案 You should check this link (last part): http://blogs.msdn.com/b/paolos/archive/2009/09/10/4-different-ways-to-process-an-xlangmessage-within-an-helper-component-invoked-by-an-orchestration.aspxCreate a custom type e.g. CustomBTXMessage [Serializable] public sealed class CustomBTXMessage : BTXMessage { public CustomBTXMessage(string messageName, Context context) : base(messageName, context) { context.RefMessage(this); } }Then you can - create a object from that type and load your xml into the body part. var customBTXMessage = new CustomBTXMessage("XLANGMessage", Service.RootService.XlangStore.OwningContext);customBTXMessage.AddPart(string.Empty, "Body");I would load the xml document in as stream and than you could load the body part from that streamcustomBTXMessage[0].LoadFrom(stream);this part of code will return you a XLANGMessage var responseMessage = customBTXMessage.GetMessageWrapperForUserCode();Good luck.Jonathan 这篇关于如何将XmlDocument转换为XLANGMessage类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-07 14:35