简体   繁体   中英

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.

Primarily ive been looking at asmx web services; 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.

Firstly really, I keep seeing the word web service proxy? 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.

What does the DLL do if users connect to the asmx file?

Also, I have referrenced asmx web services within subsequent .net solutions in the past and consumed them in my code easily. Can the .net asmx web services be consumed from other platforms & languages such as PHP or Java based or is it limited to .net?

Sorry about the very basic questions... I just though id start simple :)

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. 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. These methods usually translate to methods on the webservice.

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. 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. This is exactly the same with an 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. This WSDL is a standard and allows non .NET systems (Java, PHP in your example) to use the web service.

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

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.

In Java, this is the .jar files, in .Net it's the .dll 's, they represent code that we can access and use. We call that references.

Every time you compile a project, code is generated, compressed and compiled, generating DLL's.


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...

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

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.

You can generate the proxy manually as well by invoking a command line tool called 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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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