Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Consuming External Web Services with Microsoft Atlas  : Page 2

To consume external Web services in Atlas, you build a server-based Web service proxy to the service. The good news is that you can leverage Visual Studio and Atlas features to handle most of the work.


advertisement
Create a Proxy Client Class
There are two ways of creating Web service client proxy classes. You can use wsdl.exe at the Visual Studio command prompt to create these proxy classes or you can create a Web reference from within the Visual Studio IDE. Here's how to use wsdl.exe from your application's App_Code folder to create strongly typed proxy classes for the ZipCode Web service. Note that the following code is a single line when typed at the command prompt.

C:\projects\ZipCodeRUS\App_code> wsdl.exe http://www.tilisoft.com/ws/LocInfo/ZipCode.asmx?WSDL /namespace:Tilisoft.ZipCode

The preceding command creates a ZipCode.cs file containing a TiliSoft.ZipCode proxy class that you can use in your local code.

Next, you need to create the conduit Web service. Right click the root item in Solution Explorer, select the "Add New Item…" option from the popup menu, and then select the Web service template. I've named the service "ZipCodeConduitService."

The ZipCodeConduitService has a single function called GetZipCodeInfo that takes two string parameters: a string correlationID, and a ZIP code. When invoked, the service uses the generated proxy classes for TiliSoft Web service to retrieve results, pass them back to the ZipCodeConduitData application. To demonstrate Atlas's exception-handling capabilities, I've added a twist: If the ZIP code entered by the user is "error', GetZipCodeInfo() throws a ZipCodeConduitException. Here's the code for ZipCodeConduitService Web service class:

... [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class ZipCodeConduitService : System.Web.Services.WebService { ... [WebMethod] public ZipCodeConduitData GetZipCodeInfo(String corelationId, String zipCode) { if (zipCode.Equals("error")) { throw new ZipCodeConduitException(corelationId, "Here is an error just for you!! Enjoy!"); } ZipCode xZipCodeService = new ZipCode(); ZipCodeConduitData zipCodeConduitData = null; ZipCodeData xZipCodeData = xZipCodeService.GetInfo(zipCode); zipCodeConduitData = new ZipCodeConduitData(corelationId, zipCode, xZipCodeData); return zipCodeConduitData; } }

In the preceding code, ZipCodeConduitData is a value object used to pass information between clients and the ZipCodeConduitService. The ZipCodeConduitData class has get properties as shown below. The CorelationId property lets clients track their requests.



... using Tilisoft.ZipCode; public class ZipCodeConduitData { public ZipCodeConduitData(String corelationId, ZipCodeData data) { hydrate(corelationId, data); } String _corelationId; public String CorelationId { get { return _corelationId; } } ... String _county; public String County { get { return _county; } } String _city; public String City { get { return _city; } } ... private void hydrate(String corelationId, ZipCodeData data) { _corelationId = corelationId; if (data.ZipCodeInfo.Count > 0) { _zipCode = data.ZipCodeInfo[0].ZIPCODE; _county = data.ZipCodeInfo[0].COUNTY; _city = data.ZipCodeInfo[0].CITY; ... } } }

The ZipCodeConduitException is a C# exception class that extends System.Exception. The exception class includes the correlationId value that clients send with each request as shown in the code snippet below.

... using System; … public class ZipCodeConduitException : System.Exception { String _corelationId; public String CorelationId { get { return _corelationId; } set { _corelationId = value; } } public ZipCodeConduitException(String corelationId, String message):base(message) { _corelationId = corelationId; } }



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap