简体   繁体   English

Web服务使用和调用

[英]Web services consumption and calling

I want to ask how can I add web service into my already existing MVC 4.0 project? 我想问如何将Web服务添加到我现有的MVC 4.0项目中? I have searched on Internet, in all the links they are saying to create a new application/solution but I want to add a web service and how It will be available to call from other web sites. 我已经在Internet上搜索过,他们说所有的链接都可以创建一个新的应用程序/解决方案,但是我想添加一个Web服务以及如何从其他网站调用它。 Can somebody please tell me the steps for it. 有人可以告诉我有关的步骤。 I will be thankful to you. 我会感谢你的。 I just have basic knowledge of .Net. 我只是具有.Net的基础知识。

2)Suppose I have to call a web service from another site so how will I able to call that service if I do not have my own? 2)假设我必须从另一个站点调用Web服务,那么如果我没有自己的Web服务,该如何调用该服务?

I have searched following links: 我搜索了以下链接:

http://www.aspdotnet-suresh.com/2011/05/aspnet-web-service-or-creating-and.html http://www.codeproject.com/Articles/337535/Understanding-the-Basics-of-Web-Service-in-ASP-NET http://www.aspdotnet-suresh.com/2011/05/aspnet-web-service-or-creating-and.html http://www.codeproject.com/Articles/337535/Understanding-the-Basics-of -ASP-NET中的Web服务

Everything is rather simple. 一切都很简单。 Just read a lot about WCF service(not joking). 只是阅读了很多有关WCF服务的信息(不是在开玩笑)。 But for the beginning you can add service reference to any .Net project just by adding webservice reference . 但是从一开始,您只需添加webservice reference即可将服务引用添加到任何.Net项目。 Take a look at this article . 看一下这篇文章 Or you can generate wcf client's code via svcutil. 或者,您可以通过svcutil生成wcf客户代码。 Here is another article . 这是另一篇文章

You can consume WCF on any .Net app, either web or win. 您可以在任何.Net应用程序上使用WCF,无论是Web还是Win。 You just have to generate you wcf client and configure binding and endpoint setting. 您只需要生成wcf客户端并配置绑定和端点设置即可。 But I'd strongly recomment you to read some books about WCF. 但我强烈建议您阅读一些有关WCF的书。 At least take Jeffrey Richter's - CLR via C# or Andrew Troelsen - C# and the .NET Platform and read WCF chapters to have common knowledges. 至少通过C#或Jeff Andrew Richel's-CLR或Andrew Troelsen-C#和.NET平台,并阅读WCF章节以了解常识。

UPDATE: 更新:

It's now a huge difference working with WCF in MVC or any other project. 现在,在MVC或任何其他项目中使用WCF来说是巨大的区别。 Once you have generated a client, or you have your web reference - you do have an opportunity to call remote services via client. 生成客户端或获得Web参考之后,您确实有机会通过客户端调用远程服务。 And you can use MVC controller to run it. 您可以使用MVC控制器来运行它。 Eg 例如

 public ActionResult TestAction()
 {
   var(INewlyGeneratedClient client = new NewlyGeneratedClient("<here specify endpoint name>")
   {
     client.RunTestMethod();
   }
   return null;
 }

Keep in mind that all webservice configuration data might me located in web.config file. 请记住,所有Web服务配置数据都可能位于web.config文件中。 Make sure you have section bindings and endpoint . 确保您具有节bindingsendpoint

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM