13.07.2015 Views

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

service's web.config file.Build<strong>in</strong>g a .<strong>NET</strong> Framework Web Service ClientWhether you use <strong>Microsoft</strong> Visual Studio .<strong>NET</strong> or a simple text editor to code the .asmxfile, writ<strong>in</strong>g Web services us<strong>in</strong>g the .<strong>NET</strong> Framework is def<strong>in</strong>itely an easy task. And asyou'll see, writ<strong>in</strong>g client applications to use those services is even easier.You can call a Web service through a URL us<strong>in</strong>g either the HTTP-GET or the HTTP-POST command. You can do that also from with<strong>in</strong> an ASP.<strong>NET</strong> page us<strong>in</strong>g theWebRequest .<strong>NET</strong> Framework class. From with<strong>in</strong> Visual Studio .<strong>NET</strong>, referenc<strong>in</strong>g aWeb service is nearly identical to add<strong>in</strong>g a reference to another assembly. What youget is a proxy class through which your W<strong>in</strong>dows Forms or Web Forms application canreach its URL across port 80, just like a user's browser. In do<strong>in</strong>g so, firewall problemsdisappear and HTTP on top of Secure Sockets Layer (SSL) or any other <strong>for</strong>m ofencryption can be used to transfer data.Connect<strong>in</strong>g to a Web service is similar to connect<strong>in</strong>g to a .<strong>NET</strong> Framework remotableobject <strong>in</strong> that <strong>in</strong> both cases you end up us<strong>in</strong>g a proxy class. The big difference is <strong>in</strong> thecharacteristics of the proxy. The .<strong>NET</strong> Remot<strong>in</strong>g proxy is a dynamically created objectthat works transparently under the hood of the remote object <strong>in</strong>stance. The client hasthe impression that it is work<strong>in</strong>g with a local object that silently posts all calls to theremote object.The Web service proxy is a statically created class that must be compiled and l<strong>in</strong>ked tothe project. The .<strong>NET</strong> Framework provides a tool to generate such a class. This tool,named wsdl.exe, takes the Web service WSDL script and generates a <strong>Microsoft</strong> VisualBasic .<strong>NET</strong> or a C# class (the default) that mirrors methods <strong>for</strong> synchronous andasynchronous calls. From the client perspective, call<strong>in</strong>g <strong>in</strong>to the proxy class is a localcall. Each call, however, results <strong>in</strong> a roundtrip to the server. The follow<strong>in</strong>g commandl<strong>in</strong>e generates the C# proxy <strong>for</strong> the previously written Web service:wsdl.exe http://server/salesreport/salesreportservice.asmx?wsdlThe wsdl.exe utility is part of the .<strong>NET</strong> Framework SDK, and among its other options, itallows you to specify the protocol <strong>for</strong> the call and the language <strong>for</strong> the source code. Theutility is also silently <strong>in</strong>voked by Visual Studio .<strong>NET</strong> when you reference a Web serviceus<strong>in</strong>g the Add Web Reference menu command <strong>in</strong> Solution Explorer.The Proxy ClassThe proxy class generated <strong>for</strong> a Web service is added to the project and is <strong>in</strong> effect alocal class. The difference <strong>in</strong> the remot<strong>in</strong>g architecture is that .<strong>NET</strong> Remot<strong>in</strong>g uses adynamically generated class whose method <strong>in</strong><strong>for</strong>mation is hard-coded <strong>in</strong> the object<strong>in</strong><strong>for</strong>mation be<strong>in</strong>g marshaled—the ObjRef object. With a Web service, there is nodynamic class creation. The follow<strong>in</strong>g source code represents the proxy <strong>for</strong> the SalesReport Web Service:us<strong>in</strong>g System;us<strong>in</strong>g System.Xml.Serialization;us<strong>in</strong>g System.Web.Services.Protocols;us<strong>in</strong>g System.Web.Services;[System.Web.Services.WebServiceB<strong>in</strong>d<strong>in</strong>gAttribute(Name="Northw<strong>in</strong>d Sales Report Web ServiceSoap",471

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!