引用已发布的WCF序列化问题 [英] referencing published WCF serialization issue

查看:69
本文介绍了引用已发布的WCF序列化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个简单的BizTalk,其中包含我作为WCF发布的架构。


我可以导入将服务引用返回到visual studio进行测试,并创建一个简单的测试来调用WCF并获得Orchestration的响应。


我也可以从SoapUI调用WCF。 / p>


我遇到的问题是当我从BizTalk中的已发布架构生成xml示例时,我可以将其用作消息SoapUI,但如果我尝试在.Net(UnitTest或简单的控制台应用程序)中执行此操作,当我尝试根据引用的消息类型序列化
时,消息将失败。


经过一些检查,我可以看到新引用的消息(如果我在应用程序中创建消息)将创建与实际架构/ SoapUI消息不同的消息。


区别在于:目标名称空间将从根元素中省略,并将添加到根节点下的所有子元素。


示例:


通过BizTalk生成架构:


< ns0:请求 xmlns:ns0 =" http://HelloWorldWCF.HelloWorldWCFRqRs" >

  < ns0:TestElement> TestElement_0< / ns0:TestElement>

< / ns0:请求>



此代码中的序列化架构:


var reqMsg = new ServiceReference1.Request();
$
reqMsg.TestElement =" HellowWCF";

var x = new System.Xml.Serialization.XmlSerializer(reqMsg.GetType());
$
x.Serialize(Console.Out,reqMsg);



<?xml version =" 1.0"?>

<请求xmlns:xsi =" http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd =" http://www.w3.org/2001/XMLSchema">

< TestElement xmlns =" http://HelloWorldWCF.HelloWorldWCFRqRs" > HellowWCF< / TestElement>

< / Request>



架构设置为元素限定,属性不合格。



谢谢,Omer


解决方案


通过创建 XmlSerializerNamespaces 的实例并将命名空间对添加到对象,您可以指定XML文档中使用的前缀。


如何:限定XML元素和XML属性名称:

http://msdn.microsoft.com/en-us/library/xzys86e8.aspx


 


亲切的问候,


Tomasso Groenendijk


Blog  
Twitter


MCTS BizTalk Server 2006,2010


如果这回答你的问题,请相应标记




Hi,

I have a simple BizTalk with a schema that i publish as a WCF.

I am able to import the service reference back to visual studio for testing, and create a simple test to call the WCF and get a response for the Orchestration.

I am also able to call the WCF from SoapUI.

The issue i am having is when i generate an xml sample from the published schema in BizTalk, I am able to use it as the message in SoapUI, but if i try to do it in .Net (UnitTest or simple console application), the message fails when i try to serialize it against the referenced message type.

After some checking, I can see that the new referenced message (if i create the message in the application) will create a different message from the actual schema/SoapUI message.

the difference is: the target namespace is being omitted from the root element, and will be added to all the sub elements under root node.

Examples:

Generated schema via BizTalk:

<ns0:Request xmlns:ns0="http://HelloWorldWCF.HelloWorldWCFRqRs">
  <ns0:TestElement>TestElement_0</ns0:TestElement>
</ns0:Request>

Serialized schema from this code:

var reqMsg = new ServiceReference1.Request();
reqMsg.TestElement = "HellowWCF";
var x = new System.Xml.Serialization.XmlSerializer(reqMsg.GetType());
x.Serialize(Console.Out, reqMsg);

<?xml version="1.0"?>
<Request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<TestElement xmlns="http://HelloWorldWCF.HelloWorldWCFRqRs">HellowWCF</TestElement>
</Request>

the schema is set to element qualified , attribute unqualified.

Thanks, Omer

解决方案

Hi,

By creating an instance of XmlSerializerNamespaces and adding the namespace pairs to the object, you can specify the prefixes used in an XML document.

How to: Qualify XML Element and XML Attribute Names:
http://msdn.microsoft.com/en-us/library/xzys86e8.aspx

 

Kind regards,

Tomasso Groenendijk

Blog  |  Twitter
MCTS BizTalk Server 2006, 2010

If this answers your question please mark it accordingly


这篇关于引用已发布的WCF序列化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆