我用下面的代码来调用OData服务(这是从Odata.org的工作业务)从C#,我没有得到任何结果。
错误发生在response.GetResponseStream()
。呼叫到OData服务从C#
以下是错误:
Length = 'stream.Length' threw an exception of type 'System.NotSupportedException'
我要打电话到服务并解析其中的数据,什么是做到这一点的simpliest方式?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Net;
using System.IO;
using System.Xml;
namespace ConsoleApplication1
{
public class Class1
{
static void Main(string[] args)
{
Class1.CreateObject();
}
private const string URL = "http://services.odata.org/OData/OData.svc/Products?$format=atom";
private static void CreateObject()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "GET";
request.ContentType = "application/xml";
request.Accept = "application/xml";
using (WebResponse response = request.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
XmlTextReader reader = new XmlTextReader(stream);
}
}
}
}
}
能否请您加入,帮助您查看响应数据 –
我已经更新了我的代码的答案代码。 –