如何使用WCF DataContract将Xml架构与XmlDocument类型相关联

时间:2014-06-20 21:37:51

标签: xml web-services wcf soapui

我的任务是创建一个WCF服务操作,该操作将使用XSLT将XML从一种形式转换为另一种形式。当使用普通的旧asmx Web服务执行此操作时,我使用了XmlDocument类型的输入参数和返回类型。

输入XmlDocument需要具有关联的模式和命名空间。事实上,当我们的测试人员使用SOAP UI对asmx Web服务进行测试时,他们会收到以下错误 -

错误:输入' TXLife_Type'在命名空间' http://ACORD.org/Standards/Life/2'无法导入。属性必须是可选的,并且来自命名空间' http://schemas.microsoft.com/2003/10/Serialization/'。更改架构以便类型可以映射到数据协定类型或使用ImportXmlType或使用其他序列化程序。

我认为我真正需要的是3个命名空间,一个用于ServiceContract,一个用于输入XML参数,另一个用于返回的输出XML。我该怎么做?

1 个答案:

答案 0 :(得分:1)

用于服务合同界面。我用过这个 -

namespace MyNamespace
{
[ServiceContract(Namespace = "http://ItsAWonderfulLife.com/LifeSOA/Services/")]
public interface TX103toEAppXmlTransformServiceContract
{
    [OperationContract, XmlSerializerFormat]
    Output iGOTX103toLifeCommTest(Input input);
}

[MessageContract(WrapperNamespace = "http://ACORD.org/Standards/Life/2")]
public class Input
{
    [MessageBodyMember]
    public XElement TXLife { get; set; }
}

[MessageContract]
public class Output
{
    [MessageBodyMember]
    public XElement eAppXML { get; set; }
}  

}

对于服务实施 -

[ServiceBehavior(Namespace = "http://ItsAWonderfulLife.com/LifeSOA/Services/")]
public class TX103toEAppXmlTransform : TX103toEAppXmlTransformServiceContract
{
    ...
}