在AJAX应用中如何使用TODO服务

原创|其它|编辑:郝浩|2009-04-17 10:08:32.000|阅读 433 次

概述:在我们已经定义了所有运行我们的TODO应用程序所需要的资料,是该以启用ASP.NET AJAX的WCF服务方式暴露服务给客户端的时候了。对于这点,我们将添加一个启用AJAX的WCF服务.svc文件。同时,我们将去掉代码分离文件。

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>

在我们已经定义了所有运行我们的TODO应用程序所需要的资料,是该以启用ASP.NET AJAX的WCF服务方式暴露服务给客户端的时候了。对于这点,我们将添加一个启用AJAX的WCF服务.svc文件。同时,我们将去掉代码分离文件。

或者,我们可以添加一个XML文件或者文本文件然后将文件重新命名为ToDoService.svc即可。使用XML编辑器打开它并添加如下所示的指令:

<%@ ServiceHost Language="C#" Debug="true" Service="ServiceLibrary.ToDoService" %>

下面,我们将在web.config文件中放置运行该服务的必要配置信息。该代码如下所示:

<system.serviceModel>
    <behaviors>
     <endpointBehaviors>
      <behavior name="AspNetAjaxBehavior">
       <enableWebScript />
      </behavior>
      <behavior name="WebUI.HelloWorldServiceAspNetAjaxBehavior">
       <enableWebScript />
      </behavior>
     </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <services>
     <service name="ServiceLibrary.ToDoService">
      <endpoint behaviorConfiguration="AspNetAjaxBehavior" binding="webHttpBinding"
      contract="ServiceLibrary.IToDoService" />
     </service>
     <service name="WebUI.HelloWorldService">
      <endpoint address="" behaviorConfiguration="WebUI.HelloWorldServiceAspNetAjaxBehavior"
      binding="webHttpBinding" contract="WebUI.HelloWorldService" />
     </service>
    </services>
  </system.serviceModel>

接下来,在文件上右键属性并选择在浏览器中查看来查看运行的服务。再进入下一阶段之前,必须提到几点。在ASP.NET附带的一些特性如HTTP Context、Session等中你需要添加一个serviceHostingEnvironment 并设置aspNetCompatibilityEnabled="true" 来启用使用的WCF服务。


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com

文章转载自:IT168

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP