0
votes

I am tasked with creating a WCF service operation that is going to transform XML from one form to another using XSLT. When doing this with plain old asmx Web Services I used an input parameter of type XmlDocument and a return type of the same.

The input XmlDocument needs to have an associated schema and namespace. In fact when our tester, tests this using SOAP UI against the asmx Web Service they get the following error -

Error: Type 'TXLife_Type' in namespace 'http://ACORD.org/Standards/Life/2' cannot be imported. Attributes must be optional and from namespace 'http://schemas.microsoft.com/2003/10/Serialization/'. Either change the schema so that the types can map to data contract types or use ImportXmlType or use a different serializer.

I am thinking that what I really need is 3 namespaces one for the ServiceContract one for the input XML parameter and one for the output XML being returned. How do I do this?

1
I think I may have figured out how to associate a namespace with an XML document type. I am using MessageContract attribute with the named parameter WrapperNamespace. However, I am having a problem when I try to use this in the client as the client code that is generated does not match what is expected. The client method instead of accepting a message and returning a message, accepts nothing and returns void. Why does the generated client code not match the service contract? - John Aschenbrenner
code // this is from the IService1.cs [ServiceContract(Namespace="itsawonderfullife.com/LifeSOA/Services/"), XmlSerializerFormat] public interface IService1 { [OperationContract, XmlSerializerFormat] Output TX103toLifeCommTest(InputTx103 tx103); } [MessageContract(WrapperNamespace = "ACORD.org/Standards/Life/2"), XmlSerializerFormat] public class InputTx103 { public XmlDocument TXLife; } [MessageContract, XmlSerializerFormat] public class Output { public XmlDocument TXLife; } code - John Aschenbrenner
code// this is from the client generated code [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] Output IService1.TX103toLifeCommTest(InputTx103 request) { return base.Channel.TX103toLifeCommTest(request); } public void TX103toLifeCommTest() { InputTx103 inValue = new InputTx103(); Output retVal = ((IService1)(this)).TX103toLifeCommTest(inValue); } code - John Aschenbrenner

1 Answers

1
votes

For the service contract interface. I used this -

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; }
}  

}

For the Service implementation -

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