ODATA 使用 C# ASP.NET 4.0 的服务操作
我通过 C# ASP.NET 应用程序连接到 ODATA 服务,该应用程序具有以下服务操作:
GetItems(int? itemID, double? price)
我可以在浏览器中毫无问题地使用它,例如,
http://api.mycompany.com/companycatalogue/GetItems?itemID=4
我了解如何使用 LINQ to Entities 来使用 ODATA 服务,但不能找不到关于如何像上面在 C# 中那样使用服务操作的合理解释。我已在我的 Visual Studio 解决方案中对该服务进行了 Web 引用。
到目前为止,我对数据的日常使用有类似的情况:
using CompanyCatalogue; //my web reference
...
protected void Page_Load(object sender, EventArgs e)
{
CompanyCatalogueEntities dataContext = new CompanyCatalogueEntities (new Uri("http://api.mycompany.com/companycatalogue/"));
var result = from i in dataContext.Items select i; //just an example
//this is where I get into problems
var operationResults = CompanyCatalogue.GetItems(6, 20.5); //I just made this up
}
有什么指针吗?
I am connecting to an ODATA Service via a C# ASP.NET application, which has service operations such as:
GetItems(int? itemID, double? price)
I can consume this without issues in my browser, e.g.
http://api.mycompany.com/companycatalogue/GetItems?itemID=4
I understand how to use LINQ to Entities to consume an ODATA service, but can't find a decent explanation of how to consume service operations like the one above in C#. I have made a web reference to the service in my Visual Studio solution.
So far, I have something like this for my usual consuming of the data:
using CompanyCatalogue; //my web reference
...
protected void Page_Load(object sender, EventArgs e)
{
CompanyCatalogueEntities dataContext = new CompanyCatalogueEntities (new Uri("http://api.mycompany.com/companycatalogue/"));
var result = from i in dataContext.Items select i; //just an example
//this is where I get into problems
var operationResults = CompanyCatalogue.GetItems(6, 20.5); //I just made this up
}
Any pointers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好的,得到答案了:
OK, got the answer:
这可能对你有帮助。
此示例代码用于使用 WFC 数据服务中的服务操作。该服务操作(GetRowCount)返回整数(int)类型值。输入参数名称是“代码”
This may be help for you.
This sample code used to consume the service operation in the WFC Data Service. This service operation(GetRowCount) returns the integer(int) type value. input para name is "code"
您尝试过使用 HttpWebRequest 吗?
Have you tried using HttpWebRequest?