tags:

views:

14

answers:

0

I am trying to generate the OData Proxy for the service : http://services.odata.org/Northwind/Northwind.svc/$metadata

I am using System.Data.Services.Design.EntityClassGenerator for generating the OData proxy.

When I instantiate the EntityClassGenerator and call GenerateCode the output has no errors. But there is no code in the generated proxy code.

The same code works for my own service. But when I point it to any external service the EntityClassGenerator is not working.

Here is the code :

        HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(metadataEndpoint);
        webRequest.Method = "GET";
        webRequest.ContentType = "text/xml;encoding='utf-8";
        webRequest.Proxy = (proxy != null) ? proxy : WebRequest.DefaultWebProxy;

        using (WebResponse response = webRequest.GetResponse())
        {
            string xml = string.Empty;
            XmlReaderSettings settings = new XmlReaderSettings();
            using (TextReader reader = new StreamReader(response.GetResponseStream()))
            {
                xml = reader.ReadToEnd();
                using (XmlTextReader sourceReader = new XmlTextReader(reader))
                {
                    using (StringWriter targetWriter = new StringWriter())
                    {
                        // Generate the OData End point proxy.
                        EntityClassGenerator entityGenerator = new EntityClassGenerator(LanguageOption.GenerateCSharpCode);
                        entityGenerator.OnPropertyGenerated += new EventHandler<PropertyGeneratedEventArgs>(entityGenerator_OnPropertyGenerated);

                        IList<System.Data.Metadata.Edm.EdmSchemaError> errors = entityGenerator.GenerateCode(sourceReader, targetWriter, namespacename);

                        entityGenerator.OnPropertyGenerated -= new EventHandler<PropertyGeneratedEventArgs>(entityGenerator_OnPropertyGenerated);
                        odataProxyCode = targetWriter.ToString();
                    }
                }
            }
        }