All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
基于Gettext的asp.net网站多语言解决方案_[Asp.Net教程]
dropdownlist,datagrid数据绑定简单实现_[Asp.Net教程]
《Effective,C#》:值类型和引用类型_[Asp.Net教程]
怎么样学习PHP_[PHP教程]
ASP.NET实现数字、字符混合验证码_[Asp.Net教程]
Ajax无刷新实现图片切换特效_.net资料_编程技术
ASP.NET底层架构探索之IE6的革新_.net资料_编程技术
Apache伪静态html(URL Rewrite)设置法_[PHP教程]
在线竞拍系统的PHP实现框架_php资料_编程技术
windows下Apache2+php4+MySql5集成简明教程_[PHP教程]
Reading number is top 10 pictures
赵惟依写真2
修电脑也有这么漂亮的美女
到底是谁撞谁呀?
西游日记4
Summer is most suitable for young people to travel in China10
西游四格漫画(五)
8090后结婚的各种XX事
Discharge accidentally Actresses by the breast3
Absolutely shocked. National geographic 50 animal photographys7
西游四格漫画(一)
Download software ranking
C#COM编程指南
Tram sex maniac 2 (H) rar bag18
1400篇各类破解文章
Rio big adventure
都市狐狸姑娘传
Boxer's Top ten classic battle2
Sora aoi‘s film--Lust fan wall
Professional killers2 for Android
asp.netWeb服务器高级编程
I for your crazy
delv published in(发表于) 2014/1/27 6:47:04 Edit(编辑)
ASP.NET,Ajax调用WCFService(VS2008,beta2,简体中文版)_[Asp.Net教程]

ASP.NET,Ajax调用WCFService(VS2008,beta2,简体中文版)_[Asp.Net教程]

ASP.NET Ajax调用WCFService(VS2008 beta2 简体中文版)_[Asp.Net教程]

看见Dudu大哥写了一篇ASP.NET Ajax =》WCF(.NET 3.5 Beta 2,VS2005) 觉得挺有意思,以前没有WCF的时候我们都是调用Webservice,当然调用页面.cs里面的静态方法也可以;听说WCF的目标就是要替换以前那些实现分布式的技术,例如WebService,那我们也只好改成调用WCFService 了。到底这两种孰好孰差?大家可以讨论一下:


首先建立一个WebApplication项目,例如叫做AjaxAndWCFWebApplication:(默认支持AJAX)


你可以在项目上建立一个WCFService的文件夹,把所有的WCFService文件都放到里面;
然后建立WCFService文件,例如WCFAJaxService.svc


vs会建立三个文件,IWCFAJaxService.cs WCFAJaxService.svc WCFAJaxService.svc.cs

下面开始写代码:
IWCFAjaxService.cs 代码:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;


namespace AjaxAndWCFWebApplication.WCFService
{
[ServiceContract]
public interface IWCFAjaxService
{
//[OperationContract]
//void DoWork();
[OperationContract]
string GetServerDateTimeByName(string name);
}
}
WCFAjaxService.svc.cs 代码:



using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;


namespace AjaxAndWCFWebApplication.WCFService
{
public class WCFAjaxService : IWCFAjaxService
{
//public void DoWork()
//{
//}


public string GetServerDateTimeByName(string name)
{
return "你好:" + name + "; 现在时间是:" + DateTime.Now.ToString();
}
}
}
接下来改写:WCFAjaxService.svc 中的代码为:


<%@ ServiceHost Language="C#" Debug="true"


Service="AjaxAndWCFWebApplication.WCFService.WCFAjaxService"


CodeBehind="WCFAjaxService.svc.cs"


Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory" %>


其实就是在后面加上 Factory=.....那些。


接下来删除Web.config 中 部分,为什么呢?因为你用了


Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory",The


WebScriptServiceHostFactory class is designed to enable Windows Communication Foundation


services to be used to serve data to AJAX-enabled Web pages without having to write WCF


configuration settings.


好了,如果你现在右键WCFAjaxService.svc选择在浏览器中查看,你将会得到如下错误:
IIS 指定了身份验证方案“Ntlm, Anonymous”,但绑定仅支持一种身份验证的规范。有效的身份验证方案


为摘要、协商、NTLM、基本或匿名。请更改 IIS 设置,以便仅使用单一的身份验证方案。


这是个bug,参看:http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1922152&SiteID=1&pageid=0


可是这个是vs里集成的iis啊?怎么改?高人请赐教,我的办法是在本机的iis中建立个站点,并把这个站点


的“集成windows身份验证”前面的勾去掉,只留下一个匿名认证。





好了,接下来我们可以写Ajax代码了:


Default.aspx中的代码如下:


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"


Inherits="AjaxAndWCFWebApplication._Default" %>



"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">




无标题页














Ajax调用WCF Service


Calling a service that returns the current server time and the input name.


请输入昵称:


type="button" value="调用" onclick="ClientGetServerDateTimeByName()" />














在浏览器中打开刚才建立的网站,运行如下:


源代码下载 下载

来源:xiaozhuang的cnblogs







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.