开发者

ASP.NET WebForms - Calling Multiple API's and show result to user

开发者 https://www.devze.com 2023-04-03 07:13 出处:网络
I am working on creating a Web site like www.hipmunk.com in ASP.NET web forms. I need to pull the data from multiple API\'s and compare the rates and show the different rate options to the users.

I am working on creating a Web site like www.hipmunk.com in ASP.NET web forms. I need to pull the data from multiple API's and compare the rates and show the different rate options to the users. What is the best way to achive this? I am browsing around and see "Windows Workflow Found开发者_如何学运维ation" may be an option.

Anyone got suggestions for me? I am just looking for architectural suggestions.

Thanks

EDIT: Multiple API: - Each OTA's have different type of API's but so far I have seen everyone supports the XML/JSON format


I'm assuming that you are trying to capture the same data from each of the services, but they may each have a different calling pattern, and they will definitely represent their results differently. One way to handle the differences in each of the services is to encapsulate them using the Strategy Pattern. You would have a standard results object, but based on the list of requested services, you would use a different strategy to fill each one.

public interface IResultsStrategy {
    RateResults GetRateResults(SiteInfo site);
}

public class SpecificSiteStrategy {
    public RateResults GetRateResults(SiteInfo site) {
        //access the service through WCF, or whatever makes the most sense
        //create a new RateResults object, and fill it with the appropriate data
    }
}

public class AnotherSiteStrategy {
    public RateResults GetRateResults(SiteInfo site) {
        //access the service through a web request, or whatever makes the most sense
        //create a new RateResults object, and fill it with the appropriate data
    }
}

public class RateFetcher {
    public IEnumerable<RateResults> GetRates() {
        var rateResults = new List<RateResults();
        foreach(SiteInfo site in SitesToFetch) {
            IResultsStrategy strategy = GetStrategy(site);
            rateResults.Add(strategy.GetRateResults(site));
        }
        return rateResults;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消