I would like to call Sql Azure’s REST API to create a SQL Azure server. The method is documented here: http://msdn.microsoft.com/en-us/library/gg715274.aspx
I ran into problem. The response from this method is very simple:
<?xml version="1.0" encoding="utf-8"?><ServerName xmlns="http://schemas.microsoft.com/sqlazure/2010/12/">zpc0fbxur0</ServerName>
How do I define a DataContract class for this response?
If response were something like this:
<?xml version="1.0" encoding="utf-8"?>
<ServerName xmlns="http://schemas.microsoft.com/sqlazure/2010/12/"><Name>zpc0fbxur0</Name></ServerName>
the following class would work:
`
[DataContract(Namespace=SqlAzureConstants.ManagementNS, Name="ServerName")]
public class ServerName : IExtensibleDataObject
{
[DataMember()]
public string Name
{
get;
set;
}
public ExtensionDataObject ExtensionData
{
get;
set;
}
}
`
But I need to specify that property should be mapped to the text of the root element. Any ideas how to do this?
The
DataContractSerializeras it’s created by default cannot deserialize that XML – but if you use a constructor which sets therootNameandrootNamespaceparameters, it can be done.Another alternative is to use the
XmlSerializer, where you can use it directly.The code below shows both options, and also a WebChannelFactory implementation which uses the XmlSerializer type.