Search code examples
c#wcfdatacontract

wcf - creating datacontract


I've been tasked with writing a WCF service. (have not done this before.) I've received the xsd of the xml that I'll be receiveing and i'm trying to translate this into a datacontract. I require help though.

An example of a portion of the xml is:

<tfsChequeId xmlns="http://www.something.com/XMLSchemas/itrs/tfs/v1">
        <dic numericCode="20010411199194813505"/>
    </tfsChequeId>

What I've done so far is:

    [DataContract]
public class TFSChequeDic
{
    [DataMember]
    public string dic { get; set; }

}

How do I specify the numericCode attribute?

Any help would be gratefully received.

Kind Regards, Fiona

UPDATE A number of XSD's were provided to me. these are quite complex. On generating the datacontracts using svcutil.exe a number of errors were generated.. All of the following form:

Error: There was a validation error in the schemas provided for code generation:

Source:
Line: 85 Column: 6


Validation Error: Type 'http://www.something.com/XMLSchemas/itrs/common/v1:Docu
mentIdentifierCode' is not declared, or is not a simple type.

The generated datacontract is as follows:

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="TfsChequeId", Namespace="http://www.something.com/XMLSchemas/itrs/tfs/v1")]
public partial class TfsChequeId : object, System.Runtime.Serialization.IExtensibleDataObject
{

    private System.Runtime.Serialization.ExtensionDataObject extensionDataField;

    private www.something.com.XMLSchemas.itrs.tfs.v1.TfsChequeIdDic dicField;

    public System.Runtime.Serialization.ExtensionDataObject ExtensionData
    {
        get
        {
            return this.extensionDataField;
        }
        set
        {
            this.extensionDataField = value;
        }
    }

    [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false)]
    public www.something.com.XMLSchemas.itrs.tfs.v1.TfsChequeIdDic dic
    {
        get
        {
            return this.dicField;
        }
        set
        {
            this.dicField = value;
        }
    }
}

However I've no idea how to use this.. ie set numericCode? Any ideas/hints/tips would be gratefully received.

Fiona


Solution

  • You don't need to do it by hand. SvcUtil will generate a client proxy for you if you feed it the WSDL. Or are you creating the service itself?