问题描述
我有一个Asp.net Mvc3项目,并且在其中创建了一个ApiController.现在,我想在Windows应用程序项目中调用api.而且我不知道如何配置Global.asax或web.config文件来解决此问题.而且我不知道服务引用URL是什么(如果ApiController名称是Service且其中的方法是UpdatePrice)?
I have an Asp.net Mvc3 project and I have made a ApiController in it. Now I want to call the api in a windows application project. And I dont know how to config Global.asax or web.config file to approach this. And I dont know what would be the service reference url(If the ApiController name is Service and the method in it is UpdatePrice)?
推荐答案
您必须从应用程序向要访问的 WEBAPI 操作URL发出 HTTP 请求使用HttpClient
. WEBAPI是基于REST的HTTP服务,因此在这种情况下,与WCF不同,您只能通过HTTP访问它.
You have to make an HTTP request from the application to the WEBAPI action URL you want to access using HttpClient
. WEBAPI is a REST based HTTP service, so you can access it only via HTTP unlike WCF on this context.
您可以引用 此处 ,以获取更多信息和代码示例.
You can refer here for more information and code samples on this.
这篇关于如何从另一个.net项目中调用ApiController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!