Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6055969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:19:26+00:00 2026-05-23T08:19:26+00:00

I would like to call Sql Azure’s REST API to create a SQL Azure

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:19:27+00:00Added an answer on May 23, 2026 at 8:19 am

    The DataContractSerializer as it’s created by default cannot deserialize that XML – but if you use a constructor which sets the rootName and rootNamespace parameters, 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.

    public class StackOverflow_6399085
    {
        [XmlRoot(ElementName = "ServerName", Namespace = "http://schemas.microsoft.com/sqlazure/2010/12/")]
        public class ServerName
        {
            [XmlText]
            public string Name { get; set; }
    
            public override string ToString()
            {
                return string.Format("ServerName[Name={0}]", this.Name);
            }
        }
    
        const string XML = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ServerName xmlns=\"http://schemas.microsoft.com/sqlazure/2010/12/\">zpc0fbxur0</ServerName>";
    
        static void RunWithXmlSerializer()
        {
            XmlSerializer xs = new XmlSerializer(typeof(ServerName));
            MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(XML));
            ServerName obj = (ServerName)xs.Deserialize(ms);
            Console.WriteLine("Using XML serializer: {0}", obj);
        }
    
        static void RunWithDataContractSerializer()
        {
            DataContractSerializer dcs = new DataContractSerializer(typeof(string), "ServerName", "http://schemas.microsoft.com/sqlazure/2010/12/");
            MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(XML));
            string name = (string)dcs.ReadObject(ms);
            Console.WriteLine("Using DataContractSerializer (different name): {0}", name);
        }
    
        [ServiceContract(Namespace = "http://schemas.microsoft.com/sqlazure/2010/12/")]
        public class MockSqlAzureRestService
        {
            [WebGet]
            public Stream GetServerName()
            {
                MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(XML));
                WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
                return ms;
            }
        }
    
        [ServiceContract(Namespace = "http://schemas.microsoft.com/sqlazure/2010/12/")]
        public interface IServerNameClient
        {
            [WebGet(BodyStyle = WebMessageBodyStyle.Bare)]
            [XmlSerializerFormat]
            ServerName GetServerName();
        }
    
        static void RunWithWCFRestClient()
        {
            // Setting up the mock service
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            WebServiceHost host = new WebServiceHost(typeof(MockSqlAzureRestService), new Uri(baseAddress));
            host.Open();
    
            WebChannelFactory<IServerNameClient> factory = new WebChannelFactory<IServerNameClient>(new Uri(baseAddress));
            IServerNameClient proxy = factory.CreateChannel();
            var name = proxy.GetServerName();
            Console.WriteLine("Using WCF REST client: {0}", name);
        }
    
        public static void Test()
        {
            RunWithXmlSerializer();
            RunWithDataContractSerializer();
            RunWithWCFRestClient();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create trigger in MS SQL Server that would be call
I would like to call python script files from my c++ program. I am
I would like to call Perl script files from my c++ program. I am
I would like to call my unmanaged C++ libraries from my C# code. What
I would like to call C# service with using PHP, anyone know how to
I would like to call FindLast on a collection which implements IEnumerable , but
I would like to call a windows program within my code with parameters determined
From my bash shell I would like to call a program n times with
I have a controller action which I would like to call another controller action.
I have a Silverlight application in which I would like to call a WCF

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.