JQuery, Silverlight 公用WCF
WCF web.config配置:
<?xml version="1.0"?>
<configuration> <system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="" closeTimeout="00:30:00" openTimeout="00:30:00"
receiveTimeout="00:30:00" sendTimeout="00:30:00" maxBufferSize="2147483647"
maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<!--below config is for https-->
<!--<security mode="Transport">
<transport clientCredentialType="None" />
</security>-->
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="WcfHost.Service2">
<endpoint address="Ajax" behaviorConfiguration="AjaxBehavior"
binding="webHttpBinding" contract="WcfHost.Service2" />
<endpoint address="Siverlight"
binding="basicHttpBinding" contract="WcfHost.Service2" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="AjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer> </configuration>
在JQuery使用:
<script type="text/javascript">
var Type;
var Url;
var Data;
var ContentType;
var DataType;
var ProcessData; function WCFJSON() {
Type = "POST";
Url = "/WcfHost/Service2.svc/Ajax/GetTest";
ContentType = "application/json; charset=utf-8";
DataType = "json";
ProcessData = true;
CallService();
} function CallService() {
$.ajax({
type: Type, //GET or POST or PUT or DELETE verb
url: Url,
data: Data,
contentType: ContentType,
dataType: DataType,
processdata: ProcessData,
success: function (msg) {
ServiceSucceeded(msg);
},
error: ServiceFailed
});
} function ServiceFailed(xhr) {
alert('Service call failed: ' + xhr.status + '' + xhr.statusText);
Type = null;
varUrl = null;
Data = null;
ContentType = null;
DataType = null;
ProcessData = null;
} function ServiceSucceeded(result) {
if (DataType == "json") {
alert(result.d);
}
} $(document).ready(
function () {
WCFJSON();
}
);
</script>
WCF文件
namespace WcfHost
{
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service2
{
[OperationContract]
public void DoWork()
{
// Add your operation implementation here
return;
}
// Add more operations here and mark them with [OperationContract]
[OperationContract]
public string GetTest()
{
return "Test";
}
}
}
JQuery, Silverlight 公用WCF的更多相关文章
- silverlight与wcf双向通讯 例子
本文将建立一个silverlight与wcf双向通讯的简单实例,以下是详细步骤: 新建Silverlight应用程序,名称WCFtest.解决方案中添加WCF服务应用程序,名称WcfServiceTe ...
- SilverLight搭建WCF聊天室详细过程[转]
http://www.silverlightchina.net/html/zhuantixilie/getstart/2011/0424/7148.html 默认节点 SilverLight搭建WCF ...
- WCF入门教程(四)通过Host代码方式来承载服务 一个WCF使用TCP协议进行通协的例子 jquery ajax调用WCF,采用System.ServiceModel.WebHttpBinding System.ServiceModel.WSHttpBinding协议 学习WCF笔记之二 无废话WCF入门教程一[什么是WCF]
WCF入门教程(四)通过Host代码方式来承载服务 Posted on 2014-05-15 13:03 停留的风 阅读(7681) 评论(0) 编辑 收藏 WCF入门教程(四)通过Host代码方式来 ...
- jquery ajax调用WCF,采用System.ServiceModel.WebHttpBinding
Jquery ajax调用WCF服务 例子效果如下:原界面 点击按钮GetList get后,通过指定的Url获取数据添加到table 新建一个控制台项目,添加IContract.cs,DBServi ...
- 系列文章--Silverlight与WCF通信
Silverlight与WCF通信(一) :Silverlight通过httpBinding访问IIS宿主WCF 摘要: 首语本人在学习Silverlight 和 WCF的时候,各种问题层出不穷,在园 ...
- Silverlight调用一般性处理程序模拟Silverlight调用WCF效果(2)
[置顶] Silverlight调用一般性处理程序模拟Silverlight调用WCF效果(2) 分类: 技术2012-03-31 12:51 548人阅读 评论(0) 收藏 举报 silverlig ...
- Silverlight调用WCF(1)
[置顶] Silverlight调用WCF(1) 分类: 技术2012-03-31 12:29 940人阅读 评论(0) 收藏 举报 wcfsilverlightexceptionusersecuri ...
- XML配置silverlight ,wcf 解析xml
XML 代码: <?xml version="1.0" encoding="utf-8" ?><ChartSet xmlns:xsi=&qu ...
- 使用Task简化Silverlight调用Wcf
原文http://www.cnblogs.com/lemontea/archive/2012/12/09/2810549.html 从.Net4.0开始,.Net提供了一个Task类来封装一个异步操作 ...
随机推荐
- 【附12】grafana配置文件
一.配置文件位置 /usr/local/opt/grafana/share/grafana/default.ini /usr/local/etc/grafana/grafana.ini 二.init格 ...
- Java LinkedList源码剖析
LinkedList 本文github地址 总体介绍 LinkedList同时实现了List接口和Deque接口,也就是说它既可以看作一个顺序容器,又可以看作一个队列(Queue),同时又可以看作一个 ...
- HDU 1711 Number Sequence(KMP模板)
http://acm.hdu.edu.cn/showproblem.php?pid=1711 这道题就是一个KMP模板. #include<iostream> #include<cs ...
- .NET Core2.0应用IdentityServer4
IdentityServer4能解决什么问题 假设我们开发了一套[微博程序],主要拥有两个功能:[登陆验证].[数据获取] 随后我们又开发了[简书程序].[知乎程序],它们的主要功能也是:[登陆验证] ...
- codeforces 350 div2 D Magic Powder - 2 二分
D2. Magic Powder - 2 time limit per test 1 second memory limit per test 256 megabytes input standard ...
- ros 编译指定包
一.编译到devel目录在工作空间下(有devel文件夹的那个目录)执行 catkin_make --pkg 包名 如果报错,执行catkin_make -DCATKIN_WHITELIST_PACK ...
- DATEDIFF 和 DATEADD
/* DATEDIFF函数计算两个日期之间的小时.天.周.月.年等时间间隔总数 语法 DATEDIFF(interval, date1, date2[, firstdayofweek[, firstw ...
- kali 下程序卸载方法
ali中主要为2种卸载方法:1.apt2.dpkg 使用apt的方式有:apt-get remove [package]apt-get remove --purge # ------(package ...
- Linux访问windows共享(samba/smbclient/smbfs/cifs)
samba是一个实现不同操作系统之间文件共享和打印机共享的一种SMB协议的免费软件.●安装samba,samba-client和cifs-utils.x86_64此步将自动安装好相关依赖包:samba ...
- Try2Hack 过关技巧和密码
官网:http://www.try2hack.nl/levels 玩到第五关实在是过不去了,因为那个程序太老了,win7根本就运行不了,崩溃. 转自:http://blog.csdn.net/chin ...