简体   繁体   English

了解.NET Web服务

[英]Understanding .NET Web Services

ive been looking at .net webservices lately (never had a go before) and I wondered if anyone could help me undertsand their workings a little more. 我最近一直在研究.net Web服务(以前从未尝试过),我想知道是否有人可以帮助我进一步了解他们的工作原理。

Primarily ive been looking at asmx web services; 我主要关注的是asmx Web服务; i understand this is now legacy, but i just want to get my head around this, then i'll move onto WCF which ive read is alot better/richer. 我知道这已经成为历史,但是我只是想解决这个问题,然后我将继续学习WCF,该书的阅读能力更好/更丰富。

Firstly really, I keep seeing the word web service proxy? 首先,真的,我一直看到Web服务代理一词吗? What is this and which part of my solution is this referring too. 这是什么,我的解决方案的哪一部分也涉及到这一点。 When I create my solution, it generates a .asmx file and a DLL file in the binn directory. 创建解决方案时,它将在binn目录中生成一个.asmx文件和一个DLL文件。

What does the DLL do if users connect to the asmx file? 如果用户连接到asmx文件,DLL会做什么?

Also, I have referrenced asmx web services within subsequent .net solutions in the past and consumed them in my code easily. 另外,我过去在以后的.net解决方案中引用了asmx Web服务,并在我的代码中轻松使用了它们。 Can the .net asmx web services be consumed from other platforms & languages such as PHP or Java based or is it limited to .net? .net asmx Web服务是否可以从其他平台和语言(例如基于PHP或Java)中使用,还是仅限于.net?

Sorry about the very basic questions... I just though id start simple :) 抱歉,这是一个非常基本的问题……尽管id开始很简单:)

A Web Service Proxy is a class in your code which represents a local or remote hosted web service - it allows your other code to interact with that service as if it was just any local class in your application. Web服务代理是代码中的一个类,代表本地或远程托管的Web服务-它允许您的其他代码与该服务进行交互,就好像它只是应用程序中的任何本地类一样。 To other classes using the service, the fact that the web service may be hosted remotely is completely invisible, they just know that a class exists and has methods. 对于使用该服务的其他类,Web服务可以远程托管的事实是完全不可见的,他们只知道一个类存在并且具有方法。 These methods usually translate to methods on the webservice. 这些方法通常转换为Web服务上的方法。

The ASMX file has two elements, one being a code element just like an ASPX has an ASPX.CS in an ASP.NET webforms solution. ASMX文件包含两个元素,一个是代码元素,就像ASPXASP.NET Web 窗体解决方案中具有ASPX.CS一样。 In that example, when you compile your code, you still have an ASPX , but the ASPX.CS is compiled into a DLL to be executed by the .NET runtime. 在该示例中,当编译代码时,您仍然拥有ASPX ,但是ASPX.CS被编译为DLL并由.NET运行时执行。 This is exactly the same with an ASMX . 这与ASMX完全相同。

When you create an ASMX web service, you get an automatically generated WSDL file also - this can be viewed by appending '?wsdl' after your web service path. 创建ASMX Web服务时,还会获得一个自动生成的WSDL文件-可以通过在Web服务路径后附加“?wsdl”来查看此文件。 This WSDL is a standard and allows non .NET systems (Java, PHP in your example) to use the web service. WSDL是一个标准,并允许非.NET系统(在您的示例中为Java,PHP)使用Web服务。

Hope this helps! 希望这可以帮助!

Well, your questions are very basic, but, no one born with all the knowledge and I find myself looking back in years when I has the exact questions. 好吧,您的问题是非常基本的,但是,没有一个人天生就拥有所有的知识,当我遇到确切的问题时,我发现自己回首了几年。


DLL's DLL的

I don't know what is your programming world (PHP, Java, etc) but in programming languages (PHP is a scripting language, just like Classic ASP) there are pieces of code that are wrote by someone, some times us, and we just "hook" up to that code in order to use it. 我不知道您的编程世界是什么(PHP,Java等),但是在编程语言中(PHP是一种脚本语言,就像Classic ASP一样),有些代码是由某人编写的,有时是我们编写的,而我们只需“挂钩”该代码即可使用它。

In Java, this is the .jar files, in .Net it's the .dll 's, they represent code that we can access and use. 在Java中,这是.jar文件,在.Net中是.dll ,它们代表我们可以访问和使用的代码。 We call that references. 我们称其为参考。

Every time you compile a project, code is generated, compressed and compiled, generating DLL's. 每次编译项目时,都会生成,压缩和编译代码,并生成DLL。


Proxy 代理

If you have consumed Web Services before in .NET as you mention, you know that what you probably did was Add a Web Reference and that's it, the Web Service is ready to be consumed... 如前所述,如果您曾经在.NET中使用过Web服务,那么您知道您可能所做的就是添加一个Web引用 ,就是这样,Web服务就可以使用了。

Well, that action generated a Proxy , a class that was extracted from the Web Service Definition (WSDL) and you can now call it by simply 好了,该操作生成了一个Proxy ,该类是从Web服务定义(WSDL)中提取的,现在您可以通过简单地调用它

myWebServiceClient ws = new myWebServiceClient();
int total = ws.Add(1, 2);

So, in .NET, and so you can use a strongly typed objects, you generate a proxy prior to start codding the Web Service, in Visual Studio this act is the same as Add a Web Reference to your project. 因此,在.NET中,您可以使用强类型对象,在开始编写Web服务之前先生成一个代理,在Visual Studio中,此操作与向项目中添加Web引用相同。

You can generate the proxy manually as well by invoking a command line tool called svcutil.exe 您也可以通过调用命令行工具svcutil.exe手动生成代理。


Cross Platforms 跨平台

Because Web Services use a common language, in this case SOAP, any platform can consume a Web Service created in any other platform, as long as they follow the SOAP Standards. 因为Web服务使用一种公共语言(在本例中为SOAP),所以任何平台都可以使用在任何其他平台中创建的Web服务,只要它们遵循SOAP标准即可。

If you know PHP you can easily create a Web Service in Visual Studio where it generated your asmx file and consume it by any SOAP Library in PHP, simple by pointing to the created webservice definition, for example 如果您知道PHP,则可以轻松地在Visual Studio中创建Web服务,在该服务中生成asmx文件并由PHP中的任何SOAP库使用它,只需指向创建的Web服务定义即可,例如

htttp://localhost:6543/myservice.asmx?wsdl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM