We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(6)
先决条件:您已经拥有该服务并发布了 WSDL 文件,并且您希望从 C# 客户端应用程序调用您的 Web 服务。
有两种主要方法可以实现此目的:
A) ASP.NET 服务,这是实现 SOA 的旧方法
B) WCF,正如 John 所建议的,它是 MS 的最新框架,提供了许多协议,包括开放协议和 MS 专有协议。
逐步添加服务引用
最简单的方法是在 C# 应用程序中生成代理类(这个过程称为添加服务引用)。
我正在使用 http://www.dneonline.com/以calculator.asmx?WSDL 为例,
您应该看到生成的代理类名称和命名空间。
在我的例子中,命名空间是SoapClient.CalculatorServiceReference,代理类的名称是CalculatorSoapClient。正如我上面所说,类名可能因您的情况而异。
转到 C# 源代码并添加以下内容
现在您可以通过这种方式调用服务。
Prerequisites: You already have the service and published WSDL file, and you want to call your web service from C# client application.
There are 2 main way of doing this:
A) ASP.NET services, which is old way of doing SOA
B) WCF, as John suggested, which is the latest framework from MS and provides many protocols, including open and MS proprietary ones.
Adding a service reference step by step
The simplest way is to generate proxy classes in C# application (this process is called adding service reference).
I'm using http://www.dneonline.com/calculator.asmx?WSDL as an example
CalculatorServiceReference
(or whatever you named the named the service in the previous step).You should see generated proxy class name and namespace.
In my case, the namespace is
SoapClient.CalculatorServiceReference
, the name of proxy class isCalculatorSoapClient
. As I said above, class names may vary in your case.Go to your C# source code and add the following
Now you can call the service this way.
我已经完成了您所谈论的相当多的内容,并且平台之间的 SOAP 互操作性有一个基本规则:合同第一。不要从代码中派生 WSDL,然后尝试在不同的平台上生成客户端。任何超过“Hello World”类型的函数都很可能无法生成代码,无法在运行时对话,或者(我最喜欢的)无法正确发送或接收所有数据而不引发错误。
也就是说,WSDL 是复杂、令人讨厌的东西,我尽可能避免从头开始编写它。以下是可靠的服务互操作指南(使用 Web 引用、WCF、Axis2/Java、WS02、Ruby、Python 等):
:)
I have done quite a bit of what you're talking about, and SOAP interoperability between platforms has one cardinal rule: CONTRACT FIRST. Do not derive your WSDL from code and then try to generate a client on a different platform. Anything more than "Hello World" type functions will very likely fail to generate code, fail to talk at runtime or (my favorite) fail to properly send or receive all of the data without raising an error.
That said, WSDL is complicated, nasty stuff and I avoid writing it from scratch whenever possible. Here are some guidelines for reliable interop of services (using Web References, WCF, Axis2/Java, WS02, Ruby, Python, whatever):
</rant>
:)如果您可以让它在浏览器中运行,那么像这样简单的事情就可以工作
If you can get it to run in a browser then something as simple as this would work
查看“使用 WCF使用 PHP 的服务”。它解释了您需要的基础知识。
作为理论总结:
WCF 或 Windows Communication Foundation 是一种技术,允许定义从调用方式(底层通信方法)中抽象出来的服务。
这个想法是,您定义一个关于服务做什么和提供什么的契约,还定义另一个关于实际使用服务的通信方法(无论是 TCP、HTTP 还是 SOAP)的契约。
您可以在 此处查看文章的第一部分,解释如何创建一个非常基本的 WCF 服务。
更多资源:
将 WCF 与 PHP5 结合使用。
还可以看看 NuSOAP。如果您现在NuSphere,这是一个可以让您从 PHP 连接到 WCF 服务的工具包。
Take a look at "using WCF Services with PHP". It explains the basics of what you need.
As a theory summary:
WCF or Windows Communication Foundation is a technology that allow to define services abstracted from the way - the underlying communication method - they'll be invoked.
The idea is that you define a contract about what the service does and what the service offers and also define another contract about which communication method is used to actually consume the service, be it TCP, HTTP or SOAP.
You have the first part of the article here, explaining how to create a very basic WCF Service.
More resources:
Using WCF with PHP5.
Aslo take a look to NuSOAP. If you now NuSphere this is a toolkit to let you connect from PHP to an WCF service.
你找错地方了。您应该查找Windows 通信框架。
WCF既可以用在客户端上,也可以用在服务器上。
You're looking in the wrong place. You should look up Windows Communication Framework.
WCF is used both on the client and on the server.
在这里您可以找到一个很好的教程,用于从 .NET 客户端应用程序调用基于 NuSOAP 的 Web 服务。但在我看来,您还应该考虑 PHP 的 WSO2 Web 服务框架 (WSO2 WSF/PHP) 用于维修。请参阅 适用于 PHP 2.0 的 WSO2 Web 服务框架有力提升行业唯一用于创建 SOAP 和 REST 服务的 PHP 库。还有一个关于它的网络研讨会。
现在,在.NET世界中,考虑到互操作性问题,我也鼓励使用WCF。可以在此处找到互操作性示例,但此示例使用 PHP 客户端 + WCF 服务而不是对面的。请随意实施 PHP 服务 & WFC 客户端。
codeplex.com 上有一些与 WCF 相关的开源项目,我发现它们非常高效。这些项目对于设计和开发非常有用。实现 Win Forms 和 Windows Presentation Foundation 应用程序:智能客户端、网页客户端 和移动客户端。它们可以与 WCF 结合使用来明智地调用任何类型的 Web 服务。
一般来说,模式和模式实践团队总结了良好的实践和经验在处理 .NET 平台(特别是 Web)的各种开源项目中进行设计。因此,我认为对于任何与 .NET 客户端相关的设计决策来说,这是一个很好的起点。
Here you can find a nice tutorial for calling a NuSOAP-based web-service from a .NET client application. But IMO, you should also consider the WSO2 Web Services Framework for PHP (WSO2 WSF/PHP) for servicing. See WSO2 Web Services Framework for PHP 2.0 Significantly Enhances Industry’s Only PHP Library for Creating Both SOAP and REST Services. There is also a webminar about it.
Now, in .NET world I also encourage the use of WCF, taking into account the interoperability issues. An interoperability example can be found here, but this example uses a PHP-client + WCF-service instead of the opposite. Feel free to implement the PHP-service & WFC-client.
There are some WCF's related open source projects on codeplex.com that I found very productive. These projects are very useful to design & implement Win Forms and Windows Presentation Foundation applications: Smart Client, Web Client and Mobile Client. They can be used in combination with WCF to wisely call any kind of Web services.
Generally speaking, the patterns & practices team summarize good practices & designs in various open source projects that dealing with the .NET platform, specially for the web. So I think it's a good starting point for any design decision related to .NET clients.