惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
C
Check Point Blog
B
Blog RSS Feed
G
Google Developers Blog
H
Help Net Security
博客园 - Franky
Blog — PlanetScale
Blog — PlanetScale
H
Hackread – Cybersecurity News, Data Breaches, AI and More
量子位
Recent Announcements
Recent Announcements
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
DataBreaches.Net
小众软件
小众软件
T
The Blog of Author Tim Ferriss
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
Y
Y Combinator Blog
T
Tailwind CSS Blog
J
Java Code Geeks
MyScale Blog
MyScale Blog
雷峰网
雷峰网
有赞技术团队
有赞技术团队
博客园 - 聂微东

博客园 - 空紫竹

Crystal Report Error: Either the Crystal Reports registy key permission are insufficient or the Crystal Reports runtime is not installed correctly SSRS 例子的网站 SSRS配置 获取数据库中有默认值的所以字段 sql server xml nodes 的使用 Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0 IIS 时间问题 sql server 创建临时表 系统程序监控软件 Window 7sp1 安装vs2010 sp1 打开xaml文件崩溃 windows 2008 安装 sql server 2008 详解Silverlight中PivotViewer控件编程实例 CSS资源网址 SQL server 2008 安装和远程访问的问题 vss File for <file> (<physical file>) Was Not Found silverlight 报错超时 sql server isnumeric 函数 asp 中的getChunk(img_size) Windows 7 恢复删除的数据
JQuery, Silverlight 公用WCF
空紫竹 · 2013-07-26 · via 博客园 - 空紫竹

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";
    }
  }
}