从 C# 应用程序调用 ASP.net Web 服务

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/621440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 10:37:19  来源:igfitidea点击:

Calling ASP.net Web Service from C# Application

c#asp.netweb-servicesdesktopinvoke

提问by QAH

I have a question. How can i invoke a web service and get the result from a C# desktop application. I am making a desktop app and I want it to be able to connect to my online ASP.net web services. How is this possible?

我有个问题。我如何调用 Web 服务并从 C# 桌面应用程序中获取结果。我正在制作一个桌面应用程序,我希望它能够连接到我的在线 ASP.net Web 服务。这怎么可能?

采纳答案by Andrew Arnott

  1. In Solution Explorer, right-click your project node and select Add ServiceReference.
  2. Enter the URL where your service WSDL is located. This is usually the URL of the service itself.
  3. This generates a strongly-typed proxy class in a new Services References folder in your project.
  4. Write code in your desktop app to instantiate the proxy class and invoke methods on it. The rest works like magic. :)
  1. 在解决方案资源管理器中,右键单击您的项目节点并选择添加服务引用。
  2. 输入您的服务 WSDL 所在的 URL。这通常是服务本身的 URL。
  3. 这会在项目的新服务引用文件夹中生成强类型代理类。
  4. 在您的桌面应用程序中编写代码以实例化代理类并调用其上的方法。其余的工作就像魔术一样。:)

AB Kolan was also correct, but Add WebReference uses the old-style web services framework whereas Add ServiceReferences uses the new WCF stack. Important note: It is notrequired that the service itself use WCF for you to use WCF on the client side. WCF on the client is typically the best choice for any service, provided you can take a dependency on .NET 3.0 and above.

AB Kolan 也是正确的,但 Add WebReference 使用旧式 Web 服务框架,而 Add ServiceReferences 使用新的 WCF 堆栈。重要提示:这是不是需要服务本身使用WCF为您在客户端使用WCF。客户端上的 WCF 通常是任何服务的最佳选择,前提是您可以依赖 .NET 3.0 及更高版本。

回答by Cerebrus

This is possible the same way that you access web services from any other type of application, be it an ASP.NET page, a class library or windows service.

这与您从任何其他类型的应用程序访问 Web 服务的方式相同,无论是 ASP.NET 页面、类库还是 Windows 服务。

For an explanatory tutorial on the subject, see Accessing a Web Service from a Desktop Application.

有关该主题的说明性教程,请参阅从桌面应用程序访问 Web 服务

回答by abhilash

Add a Web Reference to the webservice in your Desktop App project reference. Doing so would generate a Proxy for the Webservice called Reference.cs You can access your webservice using the proxy.

在您的桌面应用程序项目引用中添加对 web 服务的 Web 引用。这样做会为 Web 服务生成一个名为 Reference.cs 的代理。您可以使用该代理访问您的 Web 服务。

回答by Rashedul.Rubel

Will get help how to create a webservice and consume that service:

将获得有关如何创建网络服务和使用该服务的帮助:

http://www.c-sharpcorner.com/UploadFile/0c1bb2/consuming-web-service-in-Asp-Net-web-application/

http://www.c-sharpcorner.com/UploadFile/0c1bb2/sumption-web-service-in-Asp-Net-web-application/

Thanks

谢谢