C# 使用具有 WSDL 和 XSD 文件的 Web 服务

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10753640/
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-09 15:07:35  来源:igfitidea点击:

Consuming webservice having WSDL and XSD files

c#web-services

提问by Mikayil Abdullayev

We've requested a company to write a webservice that we can use to get some information.They have sent us WSDL and XSD files. Could you please tell me how I can use these files to query data? I can do it easily if I have a link to a webservice. I just provide the link and Visual Studio generates web reference for me. After that I can use that reference just like a normal class. In this case I have no link. Just above mentioned files. Thank you.

我们已经要求一家公司编写一个我们可以用来获取一些信息的网络服务。他们已经向我们发送了 WSDL 和 XSD 文件。你能告诉我如何使用这些文件来查询数据吗?如果我有一个指向网络服务的链接,我可以很容易地做到这一点。我只提供链接,Visual Studio 会为我生成 Web 参考。之后,我可以像使用普通类一样使用该引用。在这种情况下,我没有链接。上面提到的文件。谢谢你。

采纳答案by vasile.minea

You can create a proxy (add service reference in visual studio) from a wsdl file. You can read about svcutil at http://msdn.microsoft.com/en-us/library/aa347733.aspx, but VS2010 allow you to put a wsdl file on adress when adding service reference.

您可以从 wsdl 文件创建代理(在 Visual Studio 中添加服务引用)。您可以在http://msdn.microsoft.com/en-us/library/aa347733.aspx阅读有关 svcutil 的信息,但 VS2010 允许您在添加服务引用时将 wsdl 文件放在地址上。

回答by Niranjan Singh

VS2010 can't create a web service referencefrom some WSDLs. Have to write custom wrapperfor those. OR edit your WSDL in a way so VS can consume it. For example it may be ok for you to remove web service method references for the methods that you are not planning to use if those references create trouble for you.

VS2010 无法从某些 WSDL创建 Web 服务引用。必须为那些编写自定义包装器。或者以某种方式编辑您的 WSDL,以便 VS 可以使用它。例如,如果您不打算使用的方法的 Web 服务方法引用给您带来麻烦,那么您可以删除这些引用。

Unless you're stuck with .NET 2.0, you should not use ASMX web service technology.

除非您坚持使用 .NET 2.0,否则不应使用 ASMX Web 服务技术。

You should use "Add Service Reference" and point it to the WSDL on disk. It will create a set of "proxy" classes with methods that you can call just as though it were a "normal" class.

您应该使用“添加服务引用”并将其指向磁盘上的 WSDL。它将创建一组带有方法的“代理”类,您可以像调用“普通”类一样调用这些方法。

See "How to Consume a Web Service" for a walkthrough with example.

有关示例的演练,请参阅“如何使用 Web 服务”。

Use WSDL.EXE utilityto generate a Web Service proxy from WSDL.

使用WSDL.EXE 实用程序从 WSDL 生成 Web 服务代理。

e.g.

例如

wsdl /language:CS /n:"Microsoft.SqlServer.ReportingServices2010" http://<Server 
Name>/reportserver/reportservice2010.asmx?wsdl

check this for Creating and Consuming .NET Web Services in 5 Easy Steps Articleand then Creating the Web Service Proxy

在 5 Easy Steps 文章中查看创建和使用 .NET Web 服务,然后创建 Web 服务代理

Ref:
WSDL and consume web service
consume non .NET webservice through WSDL file
How to use a WSDL

参考:
WSDL 和使用 Web 服务
通过 WSDL 文件使用非 .NET Web 服务
如何使用 WSDL