.net Web 引用和服务引用之间的区别?

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

Difference between web reference and service reference?

.netwcfasmx

提问by

What is the difference between web reference and service reference in WCF? Which is preferable in WCF?

WCF中的Web引用和服务引用有什么区别?在 WCF 中哪个更可取?

回答by Kevin Hoffman

The low-level answer here is that a Web Reference will create a client proxy class that allows your code to talk to a Web Service that is described via WSDL and communicates via SOAP or HTTP GET (other posters indicate that it is only ASMX, but Web References can also talk to Java-based Web Services or Python-based or Ruby so long as they all talk WSDL and conform to the WS-I interoperability standard).

这里的低级答案是 Web 引用将创建一个客户端代理类,该类允许您的代码与通过 WSDL 描述并通过 SOAP 或 HTTP GET 进行通信的 Web 服务对话(其他海报表明它只是 ASMX,但Web 引用还可以与基于 Java 的 Web 服务或基于 Python 或 Ruby 通信,只要它们都使用 WSDL 并符合 WS-I 互操作性标准)。

A Service Reference will create a client proxy class that communicates with a WCF-based service : regardless of whether that WCF service is a Web Service or not.

服务引用将创建一个与基于 WCF 的服务通信的客户端代理类:无论该 WCF 服务是否为 Web 服务。

回答by Christian Hayter

A Web Reference allows you to communicate with any service based on any technology that implements the WS-I Basic Profile 1.1, and exposes the relevant metadata as WSDL. Internally, it uses the ASMX communication stack on the client's side.

Web 引用允许您与基于实现 WS-I 基本概要 1.1 的任何技术的任何服务进行通信,并将相关元数据公开为 WSDL。在内部,它在客户端使用 ASMX 通信堆栈。

A Service Reference allows you to communicate with any service based on any technology that implements any of the many protocols supported by WCF (including but not limited to WS-I Basic Profile). Internally, it uses the WCF communication stack on the client side.

服务引用允许您与基于实现 WCF 支持的许多协议(包括但不限于 WS-I 基本配置文件)中的任何协议的任何技术的任何服务进行通信。在内部,它在客户端使用 WCF 通信堆栈。

Note that both these definitions are quite wide, and both include services not written in .NET.

请注意,这两个定义都非常广泛,并且都包括不是用 .NET 编写的服务。

It is perfectly possible (though not recommended) to add a Web Reference that points to a WCF service, as long as the WCF endpoint uses basicHttpBindingor some compatible custom variant.

完全有可能(虽然不推荐)添加指向 WCF 服务的 Web 引用,只要 WCF 端点使用basicHttpBinding或某些兼容的自定义变体。

It is also possible to add a Service Reference that points to an ASMX service. When writing new code, you should always use a Service Referencesimply because it is more flexible and future-proof.

还可以添加指向 ASMX 服务的服务引用。在编写新代码时,您应该始终使用服务引用,因为它更灵活且面向未来。

回答by DavidWhitney

The service reference is the newer interface for adding references to all manner of WCF services (they may not be web services) whereas Web reference is specifically concerned with ASMX web references.

服务引用是较新的接口,用于添加对各种 WCF 服务(它们可能不是 Web 服务)的引用,而 Web 引用专门与 ASMX Web 引用相关。

You can access web references via the advanced options in add service reference (if I recall correctly).

您可以通过添加服务引用中的高级选项访问网络引用(如果我没记错的话)。

I'd use service reference because as I understand it, it's the newer mechanism of the two.

我会使用服务引用,因为据我所知,它是两者中较新的机制。

回答by Brian Genisio

Service references deal with endpoints and bindings, which are completely configurable. They let you point your client proxy to a WCF via any transport protocol (HTTP, TCP, Shared Memory, etc)

服务引用处理端点和绑定,它们是完全可配置的。它们允许您通过任何传输协议(HTTP、TCP、共享内存等)将客户端代理指向 WCF

They are designed to work with WCF.

它们旨在与 WCF 一起使用。

If you use a WebProxy, you are pretty much binding yourself to using WCF over HTTP

如果您使用 WebProxy,您几乎可以将自己绑定到通过 HTTP 使用 WCF

回答by Wagner Silveira

Another point to take in consideration is that the new UI for Service Interface will give you much more flexibility on how you want to create your proxy class. For example, it will allow you to map data contracts to existing dlls, if they match (actually this is the default behaviour).

需要考虑的另一点是,Service Interface 的新 UI 将为您提供更多的灵活性来决定如何创建代理类。例如,它允许您将数据协定映射到现有的 dll,如果它们匹配(实际上这是默认行为)。