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的更多相关文章

  1. silverlight与wcf双向通讯 例子

    本文将建立一个silverlight与wcf双向通讯的简单实例,以下是详细步骤: 新建Silverlight应用程序,名称WCFtest.解决方案中添加WCF服务应用程序,名称WcfServiceTe ...

  2. SilverLight搭建WCF聊天室详细过程[转]

    http://www.silverlightchina.net/html/zhuantixilie/getstart/2011/0424/7148.html 默认节点 SilverLight搭建WCF ...

  3. 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代码方式来 ...

  4. jquery ajax调用WCF,采用System.ServiceModel.WebHttpBinding

    Jquery ajax调用WCF服务 例子效果如下:原界面 点击按钮GetList get后,通过指定的Url获取数据添加到table 新建一个控制台项目,添加IContract.cs,DBServi ...

  5. 系列文章--Silverlight与WCF通信

    Silverlight与WCF通信(一) :Silverlight通过httpBinding访问IIS宿主WCF 摘要: 首语本人在学习Silverlight 和 WCF的时候,各种问题层出不穷,在园 ...

  6. Silverlight调用一般性处理程序模拟Silverlight调用WCF效果(2)

    [置顶] Silverlight调用一般性处理程序模拟Silverlight调用WCF效果(2) 分类: 技术2012-03-31 12:51 548人阅读 评论(0) 收藏 举报 silverlig ...

  7. Silverlight调用WCF(1)

    [置顶] Silverlight调用WCF(1) 分类: 技术2012-03-31 12:29 940人阅读 评论(0) 收藏 举报 wcfsilverlightexceptionusersecuri ...

  8. XML配置silverlight ,wcf 解析xml

    XML 代码: <?xml version="1.0" encoding="utf-8" ?><ChartSet  xmlns:xsi=&qu ...

  9. 使用Task简化Silverlight调用Wcf

    原文http://www.cnblogs.com/lemontea/archive/2012/12/09/2810549.html 从.Net4.0开始,.Net提供了一个Task类来封装一个异步操作 ...

随机推荐

  1. HDU 1757 A Simple Math Problem(矩阵快速幂模板)

    题意:题意很简单,不多说了. 思路: |f(10) |       |a0 a1 a2 ...a8 a9|    |f(9)|| f(9)  |       | 1   0   0 ... 0     ...

  2. Linux 普通用户拿到root权限及使用szrz命令上传下载文件

    1.如何拿到root权限 在shell里如果看到你的命令输入行最前面显示的是 $符号,说明目前账号只有系统的普通权限. 输入:sudo su 这时能看到shell的输入行最前面已经显示的是#号,说明已 ...

  3. hdu 1370 || poj 1006 简单的中国剩余定理或者暴力

    Biorhythms Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Probl ...

  4. Django本地开发,debug模式引用静态文件

    debug为true ,不用设置static_root debug 为false ,设置static_root STATIC_ROOT = ( os.path.join(BASE_DIR, 'stat ...

  5. html 画圆

    <html> <head> <script type = "text/javascript" src = "https://d3js.org ...

  6. SQLServer随机取记录

    SQLServer本身并没有提供随机读取记录的功能,但我们可以通过一些方法来实现这个目的.本文介绍了其中几种方法并比较了各自的优劣. 方法一:直接通过Sql语句实现,如: SELECT TOP 100 ...

  7. [tixml]保存,读取

    保存: //xml的实体 TiXmlElement* rootElement = new TiXmlElement("spark"); rootElement->SetAtt ...

  8. [原][译][physX]phsyX3.3.4官方文档物理引擎基本概念和例子介绍

    世界和物体: 物理世界包括集合的场景,每个包含的物体称为演员(Actors) 每个场景(Scene)都定义了自己的参考框架包含了所有的时间和空间 在不同的场景,演员不互相影响 演员通常有三种类型:刚体 ...

  9. Socket入门之前的知识点

    Socket难点 数据粘包 心跳维持 数据丢包 性能问题 7层网络模型-OSI 基础层:物理层(Physical).数据链路层(Datalink).网络层(Network) 传输层(Transport ...

  10. 新概念 Lesson 2 Sorry, sir.

    Is this your handbag? 这是你的手提包吗? Yes,it is. /No it isn't 人称代词的主格宾格 形容性物主代词的用法 Does the man get his um ...