I created my first WCF service, designed to receive HTTP Post requests that have a message body in a strict format that I do not affect. 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 provide maximum control over XML, I decided to use the XmlSerializer instead of the DataContractSerializer with [XmlSerializerFormat].
The Account class is very simple: [XmlRoot (Namespace = " http://schemas.microsoft.com/v1.0 ")] [Serializable] public class {
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 see that he 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 d4p1 namespace aliases that have been entered. If I request a service with an XML request that does not include these aliases, the request fails with a null pointer to the Account object obtained by the AcquirePackagingData method.
At first I tried to use DataContractSerializer, but had the same problem. I was hoping to get a different result using the XMLSerializer. I read elsewhere on this forum that maybe I could use the following approach, but that didn't matter:
[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 let me know how I can change my service so that the XML request for the request contains a namespace, but not these pesky aliases d4p1?
thanks