Odata连接服务-如何使用?

时间:2018-07-16 07:17:44

标签: c# odata console-application odata-connected-service

我目前正在尝试制作一个虚拟控制台应用程序,以了解AX Web API的工作原理。

我将我的odata Web服务添加为连接服务,然后从那里不确定如何在我的主服务中引用它或进行任何获取,以调用该服务。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using Microsoft.Data.OData;
using System.IO;
using System.Xml;
namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://10.51.32.14:8101/DynamicsAx/Services/ODataQueryService/Invent");
            request.Method = "GET";
            request.ContentType = "application/x-www-form-urlencoded";
            //request.UseDefaultCredentials = true;
            //request.PreAuthenticate = true;
            request.Credentials = new NetworkCredential("admin_nc_keer", "C^Reup-rK)EH1j");
            //request.Credentials = CredentialCache.DefaultCredentials;
            try
            {
                using (WebResponse response = request.GetResponse())
                {
                    using (Stream stream = response.GetResponseStream())
                    {
                        XmlTextReader reader = new XmlTextReader(stream);
                        Console.WriteLine(" {0}={1}", reader.Name, reader.Value);
                    }
                }
            }
            catch(WebException e)
            {
                if (e.Status == WebExceptionStatus.Timeout)
                {
                    Console.WriteLine("Timeout!");
                }
                else throw;
            }
            Console.WriteLine("End!");
            Console.ReadLine();
        }
    }
}

什么都不返回...

没有为odata数据定义容器,而是一个内容类型,即

<content type="application/xml">

0 个答案:

没有答案