C# 在 ASP.NET 上通过 SOAP 调用 Web 服务的最简单方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1056185/
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
Simplest way of invoking a webservice via SOAP on ASP.NET
提问by Alex N.
I have a webservice on a remote host that I need to invoke from ASP.NET/C# class. What is the simplest way of calling a method via SOAP, given WSDL url and a method signature?
我在远程主机上有一个 web 服务,我需要从 ASP.NET/C# 类调用它。给定 WSDL url 和方法签名,通过 SOAP 调用方法的最简单方法是什么?
Given: WSDL url as string(available only at runtime, i.e. variable) Method signature(constant)
鉴于:WSDL url 作为字符串(仅在运行时可用,即变量)方法签名(常量)
Need to: Create a soap client and perform method call.
需要:创建一个soap客户端并执行方法调用。
采纳答案by rifferte
See here: http://msdn.microsoft.com/en-us/library/d9w023sx.aspx
请参阅此处:http: //msdn.microsoft.com/en-us/library/d9w023sx.aspx
Its very easy in visual studio - you simply add the web reference url and it generates the proxy stub for you.
它在 Visual Studio 中非常简单 - 您只需添加 Web 参考 url,它就会为您生成代理存根。
回答by John Saunders
The simplest thing to do is to just use "Add Service Reference" and point to the WSDL. It will generate the proxy classes for you, including a proxy method which should match the method signature you've been given.
最简单的做法是使用“添加服务引用”并指向 WSDL。它将为您生成代理类,包括一个代理方法,该方法应与您获得的方法签名相匹配。
See if you find How to Consume a Web Serviceto be helpful.
看看您是否觉得如何使用 Web 服务有帮助。