# Wednesday, April 18, 2007

The Accounting Engine has a set of addressing components that include Countries, States/Provinces, Zip/Regions, etc. The back-end of these components is composed of WCF (Windows Communication Foundation) services, business logic, data access repository (DAO) and an O/R mapper (NHibernate). I have a Smart Client to maintain those components but eventually I want to be able to use AJAX as Web Client in the future. The problem is that AJAX does not support WCF yet and it only supports ASMX services. (Complete support for WCF Services will be provided with .NET 3.5)

 Since I want to be able to maintain those components using AJAX now, I have implemented ASMX client services (aggregators) that make synchronous requests to the WCF services.

 For the benefit of those that find themselves in the same situation I will provide an outline of the steps I performed while creating the CountryService aggregation.

 First I created an ASMX Web project and added references to the Data Contract and Service Contract projects and to the System.Web.Extensions dll.

 Then I added a using System.Web.Script.Services; statement and the following Attributes:

[ScriptService]

[GenerateScriptType(typeof(CountryData))]

[GenerateScriptType(typeof(CountryListData))]

 I also added the ICountryService interface (service contract) to the Web Service class:

 public class CountryService : WebService, ICountryService

 generated the stubs for the ICountryService and added the WebMethod attributes:

 

[WebMethod]

public CountryData Save(CountryData data)

{

throw new Exception("The method or operation is not implemented.");

}

 [WebMethod]

public void Delete(int countryID)

{

throw new Exception("The method or operation is not implemented.");

}

 Now I needed a typed proxy to access the WCF service and I created that from a Visual Studio command prompt using the following command:

 wsdl /n:CyberBizSoft.Common.Services /o:CountryClient.cs /urlkey:CountryClientAddress http://localhost:1218/common/countryservice.svc?wsdl

 After including the generated file in the project I created a class variable reference to the WCF CountryService:

 CountryClient mClient = new CountryClient();

 Then added the code to all the interface stubs:

 

[WebMethod]

public CountryData Save(CountryData data)

{

   return mClient.Save(data);

}

 [WebMethod]

public void Delete(int countryID)

{

   mClient.Delete(countryID);

}

 

Finally I added the following to the web.config to specify the endpoint to communicate with:

 <appSettings>

<add key="CountryClientAddress" value="http://localhost:1218/common/countryservice.svc"/>

appSettings>

 Now I can access the services from AJAX!

posted on Wednesday, April 18, 2007 4:05:19 AM UTC  #    Comments [0]