前言

本示例用于练习使用Atlas实现ajax,所要做的是一个搜索页面,用到类Google 提供的WebService,关于google api 的获取以及注册方面的请参考使用C#调用GoogleApi一文。关于Atlas的获得请参考Ajax&atlas()调用Webservice

 

步骤

l         打开vs2005,使用atlas模板新建一个项目。在Default.aspx的源代码中在第一行的<%@ Page Language="C#" %>中添加属性Title=” Google Search”

l         将下载的the Google Web APIs Developer's Kit中的GoogleSearch.wsdl文件放入本地的服务器上,然后在VS中右键点击资源管理器中的引用,再选择添加Web引用,然后输入GoogleSearch.wsdl文件在本机服务器上的地址http://localhost/GoogleSearch.wsdl,更改Web引用名为GoogleSearch后,点击添加引用后返回。

l         添加对ajax.net的程序集AjaxPro.dll的引用,然后修改web.config文件,在其中添加如下内容:

Ajax&Atlas(二)调用Google API示例<system.web>
Ajax&Atlas(二)调用Google API示例
<httpHandlers>
Ajax&Atlas(二)调用Google API示例            
<add verb="POST,GET" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro"/>
Ajax&Atlas(二)调用Google API示例        
</httpHandlers>
Ajax&Atlas(二)调用Google API示例
</system.web>

l         然后新建一个用于存查询结果的类Result.cs,代码如下:

Ajax&Atlas(二)调用Google API示例[Serializable]
Ajax&Atlas(二)调用Google API示例
public class Result

l         然后新建一个webForm,然后将其代码文件修改为如下内容:

Ajax&Atlas(二)调用Google API示例public partial class _Default : System.Web.UI.Page 
}

l         最后回到webForm的源代码页面,进行客户端的处理。关键代码如下:

Ajax&Atlas(二)调用Google API示例<input id="Text3" type="text" />
Ajax&Atlas(二)调用Google API示例    
<input id="Button3" type="button" value="button" language="javascript" onclick="result(document.getElementById('Text3').value)" /></div>
Ajax&Atlas(二)调用Google API示例    
Ajax&Atlas(二)调用Google API示例        
Ajax&Atlas(二)调用Google API示例   
<br />
Ajax&Atlas(二)调用Google API示例    搜索结果:
<br />
Ajax&Atlas(二)调用Google API示例    
<hr />
Ajax&Atlas(二)调用Google API示例    
<table style="width: 333px">
Ajax&Atlas(二)调用Google API示例        
<tr>
Ajax&Atlas(二)调用Google API示例            
<td id="Title">
Ajax&Atlas(二)调用Google API示例            
</td>
Ajax&Atlas(二)调用Google API示例            
<td>
Ajax&Atlas(二)调用Google API示例            
</td>
Ajax&Atlas(二)调用Google API示例            
<td>
Ajax&Atlas(二)调用Google API示例            
</td>
Ajax&Atlas(二)调用Google API示例        
</tr>
Ajax&Atlas(二)调用Google API示例        
<tr>
Ajax&Atlas(二)调用Google API示例            
<td colspan="3" id="Url">
Ajax&Atlas(二)调用Google API示例            
</td>
Ajax&Atlas(二)调用Google API示例        
</tr>
Ajax&Atlas(二)调用Google API示例        
<tr>
Ajax&Atlas(二)调用Google API示例            
<td colspan="3" id="Summer">
Ajax&Atlas(二)调用Google API示例            
</td>
Ajax&Atlas(二)调用Google API示例        
</tr>
Ajax&Atlas(二)调用Google API示例    
</table>
Ajax&Atlas(二)调用Google API示例    
<span id="result">
Ajax&Atlas(二)调用Google API示例        
Ajax&Atlas(二)调用Google API示例    
</span>
Ajax&Atlas(二)调用Google API示例    
</form>
>

这样基本就完成了,启动后就能看见效果了。

另本人在vs2005下使用magicajax 0.3.0时,按网上说明对配置文件进行了修改,但是不知为什么,总是报未将对象引用设置为对象实例的错,下面是截图,望高手指点。

 

Ajax&Atlas(二)调用Google API示例Unhandled Execution Error 
Ajax&Atlas(二)调用Google API示例Object reference not set to an instance of an object.
Ajax&Atlas(二)调用Google API示例  at MagicAjax.AjaxCallHelper.GetPageHiddenDictionary(Page page, String fieldName)
Ajax&Atlas(二)调用Google API示例  at MagicAjax.AjaxCallHelper.Page_PreRender(Object sender, EventArgs e)
Ajax&Atlas(二)调用Google API示例  at System.Web.UI.Control.OnPreRender(EventArgs e)
Ajax&Atlas(二)调用Google API示例  at System.Web.UI.Control.PreRenderRecursiveInternal()
Ajax&Atlas(二)调用Google API示例  at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 0.00196226056663626 0.001046 


 

相关文章:

  • 2021-11-26
  • 2021-09-30
  • 2022-01-27
  • 2021-11-19
  • 2022-03-08
  • 2022-01-27
猜你喜欢
  • 2021-12-20
  • 2021-09-06
  • 2021-09-03
  • 2022-12-23
  • 2021-12-17
  • 2021-07-19
相关资源
相似解决方案