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类来封装一个异步操作 ...
随机推荐
- C#学习笔记(十七):委托、事件、观察者模式、匿名委托和lambert表达式
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- C#学习笔记(二):变量、数据类型和运算符
变量.数据类型 给变量赋值,如果想指定float,在数字后面加上F/f:如果想指定decimal,在数字后面加上m. 0-9:48-57 A-Z:65-90 a-z:97-122 ...
- 重拾IP路由选择:CCNA学习指南中的IP路由选择
IP路由选择技术 是网络技术的核心部分,也是目前研究的热点,其中的 动态路由选择协议 比如RIPv1,RIPv2,OSPF等,解决了数据在网络中转递的诸多问题. 在TCP/IP协议详解的学习过程中,我 ...
- UVa 10970 大块巧克力
https://vjudge.net/problem/UVA-10970 题意: 把一个m行n列的矩形巧克力切成mn个1×1的方块,需要切几刀. 思路: 可以考虑用动态规划的方法去做,当然,最简单的是 ...
- Spring 入门 web.xml配置详解
Spring 入门 web.xml配置详解 https://www.cnblogs.com/cczz_11/p/4363314.html https://blog.csdn.net/hellolove ...
- C#类头部声明样式
/******************************************************************** * * 使本项目源码前请仔细阅读以下协议内容,如果你同意以下 ...
- WiscKey: Separating Keys from Values in SSD-Conscious Storage [读后整理]
WiscKey: Separating Keys from Values in SSD-Conscious Storage WiscKey是一个基于LSM的KV存储引擎,特点是:针对SSD的顺序和随机 ...
- python 字节与字符串转化
name = 'laogaoyang' # 采用系统默认编码格式 nameBytes = name.encode('utf-8') # 先将 name 解码(采用系统默认格式),然后用 'utf-8' ...
- python3.7 安装pyqt5
pip install pyqt5
- Java 中时间处理 System.currentTimeMillis()
import org.testng.annotations.Test;import java.text.ParseException;import java.text.SimpleDateFormat ...