C# 在 webservice 的情况下如何从 WSDL 生成代理类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11801376/
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
How to generate proxy class from WSDL in case of webservice
提问by Thomas
suppose when i have only wsdl file then how can i create proxy class just to call webservice various method. how webservice related all class and its property & method will be exposed in my c# apps. can anyone help guiding me. thanks
假设当我只有 wsdl 文件时,我如何创建代理类来调用 webservice 的各种方法。webservice 相关的所有类及其属性和方法将如何在我的 c# 应用程序中公开。任何人都可以帮助指导我。谢谢
采纳答案by lesscode
You would need to use the ServiceModel Metadata Utility Tool, or Visual Studio's Add Service Reference Dialogin order to generate a client proxy for the service with which you want to communicate. The generated proxy will provide classes that abstract the service contract, and you can program your client applications to interact with these classes.
您需要使用ServiceModel Metadata Utility Tool或 Visual Studio 的添加服务引用对话框,以便为要与之通信的服务生成客户端代理。生成的代理将提供抽象服务契约的类,您可以对客户端应用程序进行编程以与这些类进行交互。
回答by Varius
回答by VRK
You can use WSDL.exe tool using command line.
您可以通过命令行使用 WSDL.exe 工具。
i.e. WseWsdl3 WSDLPath /out:MyProxyClass.cs
IE WseWsdl3 WSDLPath /out:MyProxyClass.cs
回答by user2045407
if WseWsdl3.exe is unable to create the proxy class, there is still a way.
如果 WseWsdl3.exe 无法创建代理类,仍有办法。
If you can run your service as a regular ASP.NET web application in IIS, it creates temporary ASP.NET files where the proxy class is nicely generated for you.
如果您可以在 IIS 中将您的服务作为常规 ASP.NET Web 应用程序运行,它会创建临时 ASP.NET 文件,其中很好地为您生成了代理类。
You can find it in folder:
您可以在文件夹中找到它:
C:\Windows\Microsoft.NET\Framework\vMAJOR.MINOR.BUILD\Temporary ASP.NET Files\YOUR_WEB_APP.
C:\Windows\Microsoft.NET\Framework\vMAJOR.MINOR.BUILD\Temporary ASP.NET Files\YOUR_WEB_APP。
There are some subfolders with random names, go to most recent one and look something like "App_WebReferences.XXXX.0.cs".
有一些随机名称的子文件夹,转到最近的一个,看起来像“App_WebReferences.XXXX.0.cs”。

