我完全搞不清WCF和ASMX web服务。在我的早期阶段,我使用了很多web服务,现在引入了这个叫做WCF的新东西。我仍然可以创建作为web服务功能的WCF。我想WCF里会有更多的东西。
WCF和Web服务之间有什么区别?什么时候应该分别使用?
我完全搞不清WCF和ASMX web服务。在我的早期阶段,我使用了很多web服务,现在引入了这个叫做WCF的新东西。我仍然可以创建作为web服务功能的WCF。我想WCF里会有更多的东西。
WCF和Web服务之间有什么区别?什么时候应该分别使用?
WCF完全取代了ASMX web服务。ASMX是做web服务的旧方法,WCF是做web服务的当前方法。在客户机或服务器上,所有新的SOAP web服务开发都应该使用WCF。
ASMX Web服务只能由HTTP(使用. ASMX的传统Web服务)调用。而WCF服务或WCF组件可以被任何协议(如http、tcp等)和任何传输类型调用。
第二,ASMX web服务不灵活。然而,WCF服务是灵活的。如果您创建了一个新版本的服务,那么您只需要公开一个新端。因此,服务是敏捷的,这是考虑当前业务趋势的一种非常实用的方法。
我们将WCF开发为契约、接口、操作和数据契约。作为开发人员,我们更关注业务逻辑服务,不需要担心通道堆栈。WCF是一个适用于任何类型服务的统一编程API,因此我们创建服务并使用配置信息来建立通信机制,如HTTP/TCP/MSMQ等
Keith Elder在这里很好地比较了ASMX和WCF。来看看。
ASMX和WCF的另一个比较可以在这里找到-我不100%同意那里的所有观点,但它可能会给你一个想法。
WCF基本上是“立体立体上的ASMX”-它可以是ASMX所能做的一切-再加上更多!
ASMX 是:
易于编写和配置 仅在IIS中可用 只能从HTTP调用
WCF可以是:
托管在IIS,一个Windows服务,一个Winforms应用程序,一个控制台应用程序-你有完全的自由 用于HTTP (REST和SOAP), TCP/IP, MSMQ和许多更多的协议
简而言之:WCF将完全取代ASMX。
在MSDN上查看WCF开发者中心。
更新:链接似乎是死的-试试这个:什么是Windows通信基金会?
这是一个非常老的问题,但我认为ASMX的好处没有得到公平的描述。虽然不是很灵活,但ASMX web服务非常易于使用和理解。虽然WCF更加灵活,但它的建立和配置也更加复杂。
只要您添加文件,ASMX web服务就可以作为web服务引用进行添加。(假设您的项目构建完成)
对于简单的开发工作流程 创建webservice ->运行webservice ->添加webservice引用,ASMX webservice很少会出错,很少会配置错误,这就是它的优点。
对于那些断言WCF取代ASMX的人,我的回答是,WCF需要添加一个精简的K.I.S.S.配置模式,以便完全取代ASMX。
示例web。ASMX web服务的配置:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings />
<system.web>
<compilation targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
关于asmx web服务在WCF上的简单性,有很多讨论。让我在这里澄清几点。
Its true that novice web service developers will get started easily in asmx web services. Visual Studio does all the work for them and readily creates a Hello World project. But if you can learn WCF (which off course wont take much time) then you can get to see that WCF is also quite simple, and you can go ahead easily. Its important to remember that these said complexities in WCF are actually attributed to the beautiful features that it brings along with it. There are addressing, bindings, contracts and endpoints, services & clients all mentioned in the config file. The beauty is your business logic is segregated and maintained safely. Tomorrow if you need to change the binding from basicHttpBinding to netTcpBinding you can easily create a binding in config file and use it. So all the changes related to clients, communication channels, bindings etc are to be done in the configuration leaving the business logic safe & intact, which makes real good sense. WCF "web services" are part of a much broader spectrum of remote communication enabled through WCF. You will get a much higher degree of flexibility and portability doing things in WCF than through traditional ASMX because WCF is designed, from the ground up, to summarize all of the different distributed programming infrastructures offered by Microsoft. An endpoint in WCF can be communicated with just as easily over SOAP/XML as it can over TCP/binary and to change this medium is simply a configuration file mod. In theory, this reduces the amount of new code needed when porting or changing business needs, targets, etc. Web Services can be accessed only over HTTP & it works in stateless environment, where WCF is flexible because its services can be hosted in different types of applications. You can host your WCF services in Console, Windows Services, IIS & WAS, which are again different ways of creating new projects in Visual Studio. ASMX is older than WCF, and anything ASMX can do so can WCF (and more). Basically you can see WCF as trying to logically group together all the different ways of getting two apps to communicate in the world of Microsoft; ASMX was just one of these many ways and so is now grouped under the WCF umbrella of capabilities. You will always like to use Visual Studio for NET 4.0 or 4.5 as it makes life easy while creating WCF services. The major difference is that Web Services Use XmlSerializer. But WCF Uses DataContractSerializer which is better in Performance as compared to XmlSerializer. That's why WCF performs way better than other communication technology counterparts from .NET like asmx, .NET remoting etc.
不要忘记,我是那些喜欢asmx服务胜过WCF的人之一,但那时候我还不太了解WCF服务及其功能。我很害怕WCF配置。但是我敢于尝试自己写一些WCF服务,当我对WCF有了更多的了解后,现在我对WCF没有任何顾虑了,我把它们推荐给任何人。 编码快乐! !