如何在 C# 中使用 WSDL 文件使用 WebService
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/13407156/
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 Consume a WebService using WSDL files in C#
提问by franciscovalera
So I have two wsdl files(xml based) and I need to use them to consume a web service. Not sure where to start? I'm trying to add them in my Visual Studio Project Solution by clicking on "Add Service Reference" but I need an URL.
所以我有两个wsdl 文件(基于 xml),我需要使用它们来使用 Web 服务。不知道从哪里开始?我试图通过单击“添加服务引用”将它们添加到我的 Visual Studio 项目解决方案中,但我需要一个 URL。
Should I add them to a Virtual Directory? If so, how?
我应该将它们添加到虚拟目录吗?如果是这样,如何?
Thanks in advance
提前致谢
采纳答案by CodeZombie
You already found the solution. Use the "Add Service Reference" dialog and make sure your service is accessible by a URL. To do this either request the URL by the people offering the service or deploy the service in IIS.
您已经找到了解决方案。使用“添加服务引用”对话框并确保您的服务可通过 URL 访问。为此,请由提供服务的人员请求 URL 或在 IIS 中部署服务。
Personally I would forget about svcutil.exe. If you have Visual Studio, it is much easier to add and update the service reference using the excellent integration of web services in Visual Studio.
我个人会忘记 svcutil.exe。如果您有 Visual Studio,则使用 Visual Studio 中出色的 Web 服务集成来添加和更新服务引用要容易得多。
回答by EkoostikMartin
You can use the wsdl.exe tool which comes with Visual Studio (in there you can specify a local file path to your wsdl file) -
您可以使用 Visual Studio 附带的 wsdl.exe 工具(您可以在其中指定 wsdl 文件的本地文件路径)-
http://msdn.microsoft.com/en-us/library/d2s8y7bs(VS.100).aspx
http://msdn.microsoft.com/en-us/library/d2s8y7bs(VS.100).aspx
回答by lockstock
You can add a service reference by using the path to the wsdl files.
您可以使用 wsdl 文件的路径添加服务引用。
回答by Jesse C. Slicer
You can use svcutil.exeas such:
您可以像这样使用svcutil.exe:
svcutil.exe /language:cs /out:MyServiceProxy.cs /config:app.config c:\path\to\my.wsdl
svcutil.exe /language:cs /out:MyServiceProxy.cs /config:app.config c:\path\to\my.wsdl


