学Silverlight 2系列(25):综合实例之Live Search
2008-10-03 11:38:41 来源:WEB开发网在ASMX中对返回的结果进行一些处理,Silverlight程序最后将直接调用ASMX。在调用Live Search时需要指定应用程序ID以及本地化的信息等,查询的参数将在Silverlight程序中调用时传入。
[WebMethod]
public SearchResultItem[] DoSearch(string query)
{
MSNSearchPortTypeClient s = new MSNSearchPortTypeClient();
SearchRequest searchRequest = new SearchRequest();
int arraySize = 1;
SourceRequest[] sr = new SourceRequest[arraySize];
sr[0] = new SourceRequest();
sr[0].Source = SourceType.Web;
searchRequest.Query = query;
searchRequest.Requests = sr;
searchRequest.AppID = "C0680205851CCC0E38946DB8FF74156C1C826A86";
searchRequest.CultureInfo = "zh-CN";
SearchResponse searchResponse;
searchResponse = s.Search(searchRequest);
List<SearchResultItem> lists = new List<SearchResultItem>();
foreach (SourceResponse sourceResponse in searchResponse.Responses)
{
Result[] sourceResults = sourceResponse.Results;
foreach (Result sourceResult in sourceResults)
{
SearchResultItem item = new SearchResultItem();
if ((sourceResult.Title != null) && (sourceResult.Title != String.Empty))
item.Title = sourceResult.Title;
if ((sourceResult.Description != null) && (sourceResult.Description != String.Empty))
item.Description = sourceResult.Description;
if ((sourceResult.Url != null) && (sourceResult.Url != String.Empty))
item.Url = sourceResult.Url;
lists.Add(item);
}
}
return lists.ToArray();
}
测试一下我们的服务是否正常:
Tags:Silverlight 系列 综合
编辑录入:爽爽 [复制链接] [打 印]- ››silverlight全屏显示图片
- ››Silverlight MVVM 模式(一) 切近实战
- ››Silverlight for Windows Phone 7开发系列(1):...
- ››Silverlight for Windows Phone 7开发系列(2):...
- ››Silverlight for Windows Phone 7开发系列(3):...
- ››Silverlight for Windows Phone 7开发系列(4):...
- ››Silverlight for Symbian
- ››Silverlight3系列(四)数据绑定 Data Binding 1
- ››综合数据管理:数字时代的数据养育
- ››综合 JSF 和 Dojo 小部件创建更好的用户体验
- ››silverlight2 游戏 1 你能坚持多少秒
- ››Silverlight开发实践--PicZoomShow
更多精彩
赞助商链接