5

I've built my first ever WCF service designed to receive HTTP Post requests that have a message body in a strict format that I have no influence over. Here is an example:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <AcquirePackagingData xmlns="mydomain.com">
      <Account xmlns="http://schemas.microsoft.com/v1.0">
        <AssetIdentifier>ergegdgsdyeryegd</AssetIdentifier>
      </Account>
    </AcquirePackagingData>
  </s:Body>
</s:Envelope>

The only bit that will change with each request is the value of the AssetIdentifier.

My wcf service contract is as follows:

To given myself maximum control over the XML, I have opted to use XmlSerializer instead of DataContractSerializer by using [XmlSerializerFormat] .

The Account class is very simple to: [XmlRoot(Namespace = "http://schemas.microsoft.com/v1.0")] [Serializable] public class Account {

    private string m_AssetIdentifier;

    [XmlElement]
    public string AssetIdentifier
    {
        get { return m_AssetIdentifier; }
        set { m_AssetIdentifier = value; }
    } 

}

The problem occurs when I make a request to this service. When I use the WCF Test Client I can see that it has made the following request:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://schemas.microsoft.com/DRM/2007/03/protocols/ILGIContentProtection/AcquirePackagingData</Action>
  </s:Header>
  <s:Body>
    <AcquirePackagingData xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols">
      <challenge xmlns:d4p1="http://schemas.microsoft.com/DRM/2007/03/protocols/AcquirePackagingData/v1.0">
        <d4p1:AssetIdentifier>ergegdgsdyeryegd</d4p1:AssetIdentifier>
      </challenge>
    </AcquirePackagingData>
  </s:Body>
</s:Envelope>

Note the presence of the d4p1 namespace aliases that have been introduced. If I request the service with request XML that does not include these aliases the request fails with a null pointer on the Account object received by the AcquirePackagingData method.

I originally tried using the DataContractSerializer but had the same problem. I hoped i'd get a different result using the XMLSerializer. I read elsewhere on this forum that maybe i could use the following approach but it made no difference:

[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://schemas.microsoft.com/v1.0")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://schemas.microsoft.com/v1.0", IsNullable = false)] 
public class Account
{
....
}

Please can anyone let me know how I can modify my service so that the request XML includes the namespace but not those pesky d4p1 aliases?

Thanks

0 Answers0