0

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

我将我的 odata webservice 添加为连接服务,并且从那里不确定我如何在我的 main 中引用它或对服务进行任何 get 调用。

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">
4

0 回答 0