Tuesday (6/20/2006)
I gave a assigned a task to my developer. What I asked her was to create a code so when I go call different webservices assuming like Google search, MSN search, Amazon search, yahoo search, etc., each provider might have different wsdl definitions for their webservice, but I should not change my code as and when I add a new search provider. Essentially my search code should be like the following
string [] searchResults = searchProvider.Search(”Joke of the day”);
She tried for couple days and finally came back and said that how can she write a code that can not be changed when she adds a new provider. Because google's search wsdl may be like Google.doGoogleSearch, while Msn may be like Msn.SearchEverywhere and yahoo may be like yahoo.SearchUniverse, etc.,
After thinking about the solution I decided to write the code myself. I always knew generating .cs file using WSDL gives more flexibility but never really changed the .cs file to make use of it. Hey, finally I did...
Friday (6/23/2006)
I created another project called IGateway which has a public interface
namespace myInterfaces;
public interface IGateway
{
string [] Search(string What);
}
I put all the Gateways in a separate project called SearchProviders and added reference to IGateway project to it.
I call .cs file generated by WSDL as Gateway (GoogleGateway.cs, MSNGateway.cs, YahooGateway.cs)
Now I edit the GoogleGateway.cs to add the following
using
myInterfaces;
I put all the WSDL files in a new project called SearchGateways
change the class definition generated by WSDL to implement IGateway interface
public
class GoogleSearchService : System.Web.Services.Protocols.SoapHttpClientProtocol, IGateway {
Now add a public method that implements Search Function from IGateway like this
public string[] Search(string SearchWhat)
{
return this.doGoogleSearch(SearchWhat);
}
Obviously I have oversimplied the sample function here because doGoogleSearch has more funtions and it does not return a string array as parameter, but I guess you can figure that out.
All I need to do in my actual application that needs to perform a search I need to use reflection to create an object in runtime of type IGateway (AssemblyName and TypeName can be read from configuration file) to perform search. If I add a new SearchProvider I need to generate gateway file for that provider and change only that file and recompile only my SearchGateways project and copy the assembly.
Saturday (6/24/2006)
Family out on trip, sleep long hour, wakeup, eat, sleep, wakeup, eat, sleep... you get the idea for the weekend