2

Here's the situation. I have two WCF services, 1 is a BizTalk service, the other is a plain 'ol WCF service used for querying a data repository. I have a test application that has service references added to both of these services. I'm using HL7v3 schemas for passing data to and from both of these services.

It appears the BizTalk WCF proxy classes get generated using System.Xml.Serialization but the other non-BizTalk proxy comes across with everything using System.Runtime.Serialization.

I can deserialize fine using the BizTalk proxy classes, but not so using the other. The error that I get while trying to do so is:

"The targetNamespace parameter 'urn:hl7-org:v3' should be the same value as the targetNamespace 'http://schemas.datacontract.org/2004/07/' of the schema."

When you look at the Reference.cs file, this error makes sense, because:

[System.Runtime.Serialization.DataContractAttribute(Name="RCMR_IN000029UV01MCCI_MT000100UV01Message", Namespace="http://schemas.datacontract.org/2004/07/")]

So, I did some researching and found you can force the WCF service to use the XmlSerializer rather than the DataContract by adding an attribute to the Service/Method declarations:

[XmlSerializerFormat(Style=System.ServiceModel.OperationFormatStyle.Document)]

I noticed then in the Reference.cs that the System.XmlSerialization is now being used and the 2 Reference.cs files start to look very similar.

Now, the final problem is thus:

After switching the XMLSerializer rather than DataContract, I can't actually generate an instance of the Proxy class (which is an HL7v3 RCMR_IN000029UV01) because the root node (which ultimate becomes the object type) does not come across when the proxy classes are generated. So when it comes to deserializing (or just trying to create an instance) I can't do it eg: XmlSerializer pXmlSerializer = new XmlSerializer(RCMR_IN000029UV01); because the RCMR_IN000029UV01 doesn't exist anywhere.

The service itself is quite simple:

    [ServiceContract (Namespace="urn:hl7-org:v3")]
[XmlSerializerFormat(Style = System.ServiceModel.OperationFormatStyle.Document)]
public interface IRequestCDAService
{

    [OperationContract]
    string GetData(RCMR_IN000029UV01 query);

    [OperationContract]
    string GetDataByXML(XmlDocument queryXml);

    [OperationContract]
    CompositeType GetDataUsingDataContract(CompositeType composite);
}

However, I'm not too experienced with WCF services yet, so I'm not sure if there is something I'm missing in terms of attributes, etc.

It appears the only real difference is the proxy class is missing the actual constructor for the root node of the schema, here is what is looks like in the BizTalk service's proxy class:

    public partial class RCMR_IN000002UV01 : RCMR_IN000002UV01MCCI_MT000100UV01Message {

    private string iTSVersionField;

    public RCMR_IN000002UV01() {
        this.iTSVersionField = "XML_1.0";
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAttributeAttribute()]
    public string ITSVersion {
        get {
            return this.iTSVersionField;
        }
        set {
            this.iTSVersionField = value;
            this.RaisePropertyChanged("ITSVersion");
        }
    }
}

But when you look at the reference.cs for the other (Non-BizTalk) service, the

   public RCMR_IN000029UV01() {
    this.iTSVersionField = "XML_1.0";
}

is missing from the class definition. What am I missing?

EDIT: I forgot to mention The webservice is exposing these RCMR objects based on a classfile generated from the HL7v3 RCMR_IN000029UV01 schema using xsd.exe. In other words, it's not a class that I created myself.

Bensonius
  • 1,501
  • 1
  • 15
  • 39

1 Answers1

1

The problem is not that the default constructor was not added to the non-biztalk service. The C# compiler will generate a default constructor if one is not in the code.

It may be that you are missing the [XmlRoot] attribute on the RCMR_IN000029UV01 class.

Ryan Gross
  • 6,423
  • 2
  • 32
  • 44
  • I thought of that at one point as well, but it is indeed present in the generated class that the webservice exposes: `[System.Xml.Serialization.XmlRootAttribute(Namespace="urn:hl7-org:v3", IsNullable=false)]` – Bensonius Feb 05 '13 at 16:19