Monday, April 23, 2007

NET Remoting, Web Services etc.

Web Service concepts

  • .NET Remoting

It is mainly related to interprocess communication.
The processes can be within the same computer, computers on the same network or even the computers across different networks.
.NET Remoting enables these remote processes to communicate with each other.
.NET Remoting supports communication over different protocols.

In the past, the interprocess communication was handled by DCOM (Distributed-Component Object Model). But DCOM did not support different platforms and had some drawbacks related to firewalls. It communicated over ports that are usually blocked by firewalls. (can we still call the firewall a "firewall" if many ports are open?? ) Port 80 might be used but in that case, the firewall has to support binary traffic on port 80. (Q: What is binary traffic?)

Now that we have some practice with Web Services, we can compare it to .NET Remoting.

What was Web Services anyway??
-Web Services enable applications to pass messages to each other regardless of their platform, programming language and object model.
-Web services know nothing about the client making the request.
-It only receives a message and responds to it in a format called SOAP (Simple Object Access Protocol).

*Web Services ONLY use HTTP protocol to communicate. .NET Remoting can use any protocol!
*Web Services is stateless and creates a new object each time it receives a request. .NET Remoting has state management options, supports callbacks.
*Objects are serialized using XML included in SOAP messages. No other way than XML in Web Services. .NET Remoting does not work if the data types are not defined. This is a limit to using different data types if there is not support for it. However, objects can be passed by value or by reference.
*Web Services can operate across different platforms. .NET Remoting requires the applications built on .NET.


In .NET remoting, the communication occurs over channels. The applications use the channels to send or receive messages. There are two existing channels: TcpChannel and HttpChannel in .NET Remoting.

Below is a snapshot of the application I have tested. The one on top is the Server. The window at the bottom is the client making the request. The Server responds to the client with a message.



Links:
http://www.developer.com/net/cplus/article.php/10919_1479761_1


  • SOAP (Simple Object Access Protocol)

SOAP is a protocol that enables the applications to communicate across the computer networks.
The communication is achieved by using XML format.
The communication occurs usually using HTTP.

Below is a snapshot of the soap messages created by the HelloWorld Web Service that we have created. The top block makes the request and the bottom block displays the corresponding response.
Note that, only the return types are specified, not the returned values. Because the Web Service method has not been invoked yet.
OK, SOAP does this, SOAP does that. Where does this all fit in real-world? Where do I use SOAP? Please add the best practices of using SOAP to my post here.
There is one application I can only guess for the time being. It might not be correct though.
Let's take the example of a Small Business web site. Assume that, this site is selling computer parts. Nowadays, we see that there are options on the web site when we are about to make a purchase, like "Click here to check how many items are available." When you click this link, the small business web site connects to the Distributor's web site or database and queries the most current value. Of course, the distributor wouldn' t prefer to provide access to their database to everyone. They would prefer an interface instead. So, these kind of messaging between different web sites might be good application for SOAP. Remember, it is just my understanding and might not be true.

  • XML (Extensible Mark-up Language)

XML is like HTML. The main difference is that we can specify and use our own tags.
Every tag has to have a closing tag OR needs to be self-closing, using the forward slash /.
Needs to conform to the rules of being Well-formed.
Needs to be valid.

For months, I have not understood why XML became so popular! You see books written on XML everywhere, people talk about it etc. Still having trouble understanding it.

For example, Microsoft has released Small Business Starter Kit in ASP.NET. Using this kit, you can advertise your products, display their pictures, specify the price, edit the definition etc. All these features of the product are defined within an XML file. You can easily edit these attributes I mentioned (item definition, price etc.) even by a text editor. For instance, the previous price of item A is $1175, then open the XML file and easily change it to $1250. But, what if you need to update each of the one-thousand items' prices?! See my post in ASP.NET forums. http://forums.asp.net/thread/1408825.aspx

My only understanding is that, the XML format is both machine and human readable format. Everything is written in simple text and there is no encryption. For instance, you can not easily access a database so easily; you need to have at least MS Access installed to access your tables, in case of an Access Database. SQL server requires correct connection string, username/password etc. Why bother with these? Open the XML document with your Notepad and reach the information you need and even edit the file yourself!

  • WSDL (Web Service Definition Language) - wsdl.exe

-Having its description based on XML, WSDL defines the communication used on Web Services.
-The services are described as a collection of ports (or network endpoints).
-The definitions are abstract and they are separated from the actual use which clarifies the ports being used at that instance. This allows to use the same codes again and again.
-The client connects to the web site and uses WSDL to discover what services are offered.
-After determining the available services, one of the functions or methods can be called using SOAP.

  • Web Services Discovery Tool - disco.exe
-Discovers (queries, interrogates) and saves the documents of each of the XML Web Services in a particular web site to the local disk.
-disco.exe and wsdl.exe are used in conjunction with the web services.
-Produces .wsdl, .disco, .xsd and .discomap files which can later be used by wsdl.exe as an input to create XML Web Service clients.
1. Use disco.exe to discover available services and download
2. Then use wsdl.exe to produce the proxy files.
3. Compile the project.

Generating a proxy class for our code (When we are not allowed to add a web reference)
> wsdl /out:C:\Webservice_HelloWorld.cs C:\Webservice_HelloWorld.wsdl

1. wsdl parses the web service description.
2. Generates proxy classes.
3. Consumer uses these proxy classes to call the methods of that particular web service.

A useful link for above process.

-Not all web services have to provide support for public discovery. It can be used privately.

  • UDDI (Universal Description Discovery and Integration)
is an XML-based registry for businesses to list their company on the internet.
The companies can list themselves with name, location... and the web services they offer.
By this way, companies can have their systems inter-operating with other companies.

Case study: Different types of digital photography software do not inter operate and many people find it difficult to print their digital photos. The companies producing digital cameras have come together to support networks where end-users can easily have their digital photos printed.

2 comments:

Anonymous said...

Keep up the good work.

dotneteasy said...

Thanks. Gained much more experience since I've written the blog. It's fun :)