1

This should be straight forward, but after a lot of forum browsing I still havent found a solution. Here goes:

I have a fairly simple Interface defined like this:

[ServiceContract(Namespace = "test-contract")]
public interface IDebitor : Source.BaseInterface.IBase
{
    [OperationContract]
    DebitorResult CreateUpdateDebitorPerson(DebitorPerson person)
}

[DataContract(Namespace = "test-person")]
public class DebitorPerson
{
    #region FIELDS

    // Line
    string senderSystemId;
    string firstName;
    string lastName;
    string address1;
    string address2;
    string postalCode;
    string city;
    string areaCode;
    string cprNumber;
    string payingCustomerId;
    string paymentCode;
    string languageCode;

    #endregion

    #region Propperties

    [DataMember(IsRequired = true, Order = 1)]
    public string SenderSystemId
    {
        get { return senderSystemId; }
        set { senderSystemId = value; }
    }


    [DataMember(IsRequired = true)]
    public string FirstName
    {
        get { return firstName; }
        set { firstName = value; }
    }

    [DataMember(IsRequired = true)]
    public string LastName
    {
        get { return lastName; }
        set { lastName = value; }
    }

    [DataMember(IsRequired = true)]
    public string Address1
    {
        get { return address1; }
        set { address1 = value; }
    }

    [DataMember(IsRequired = false)]
    public string Address2
    {
        get { return address2; }
        set { address2 = value; }
    }

    [DataMember(IsRequired = true)]
    public string PostalCode
    {
        get { return postalCode; }
        set { postalCode = value; }
    }

    [DataMember(IsRequired = true)]
    public string City
    {
        get { return city; }
        set { city = value; }
    }

    [DataMember(IsRequired = true)]
    public string AreaCode
    {
        get { return areaCode; }
        set { areaCode = value; }
    }

    [DataMember(IsRequired = true)]
    public string CprNumber
    {
        get { return cprNumber; }
        set { cprNumber = value; }
    }

    [DataMember(IsRequired = false)]
    public string PayingCustomerId
    {
        get { return payingCustomerId; }
        set { payingCustomerId = value; }
    }


    [DataMember(IsRequired = true)]
    public string PaymentCode
    {
        get { return paymentCode; }
        set { paymentCode = value; }
    }

    [DataMember(IsRequired = false)]
    public string LanguageCode
    {
        get { return languageCode; }
        set { languageCode = value; }
    }

    #endregion
}

The service run just fine, but the corresponding soap xml is not what I exspected.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:test="test-contract" xmlns:test1="test-person">
   <soapenv:Header/>
   <soapenv:Body>
      <test:CreateUpdateDebitorPerson>
         <!--Optional:-->
         <test:person>
            <test1:Address1></test1:Address1>
            <!--Optional:-->
            <test1:Address2></test1:Address2>
            <test1:AreaCode></test1:AreaCode>
            <test1:City></test1:City>
            <test1:CprNumber></test1:CprNumber>
            <test1:FirstName></test1:FirstName>
            <!--Optional:-->
            <test1:LanguageCode></test1:LanguageCode>
            <test1:LastName></test1:LastName>
            <!--Optional:-->
            <test1:PayingCustomerId></test1:PayingCustomerId>
            <test1:PaymentCode></test1:PaymentCode>
            <test1:PostalCode></test1:PostalCode>
            <test1:SenderSystemId></test1:SenderSystemId>
         </test:person>
      </test:CreateUpdateDebitorPerson>
   </soapenv:Body>
</soapenv:Envelope>

Why does the element belongs to test-contract and not testperson as defines in the interface? Can someone help me out here?

1 Answer 1

1

Because the element itself ("<person>") is defined at the service contract level, not at the data contract level. You either get <test-contract:person> (if you use it in a service) or <test-person:DebitorPerson> (if you serialize the instance in a standalone way with the DataContractSerializer). To mix the two somehow (e.g. <test-person:person>) would be inconsistent - why should the namespace come from the DataContract level, and the name from the ServiceContract level?

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your quick reply. Head-of-office has an idea that the input (person) namespace should be completely seperated from the service namespace (CreateUpdateDebitorPerson). The idea is that the namespace could hold version information. Would it be possible to archieve some like <test1:person>?
In the old ASMX world, the namespace would have come from the data contract level (not called a data contract in asmx, but it would have come from the serializable class). This changes in WCF where the namespace now comes from the service level. Can this be altered if I am switching to wcf and need to retain compatibility with clients?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.