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

推荐订阅源

W
WeLiveSecurity
T
The Exploit Database - CXSecurity.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Security @ Cisco Blogs
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
Microsoft Azure Blog
Microsoft Azure Blog
罗磊的独立博客
F
Full Disclosure
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Engineering at Meta
Engineering at Meta
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Threatpost
I
Intezer
V2EX - 技术
V2EX - 技术
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
小众软件
小众软件
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
N
News | PayPal Newsroom
MyScale Blog
MyScale Blog
AI
AI
Vercel News
Vercel News
Spread Privacy
Spread Privacy
美团技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
L
LINUX DO - 热门话题
U
Unit 42
L
LangChain Blog
Recent Announcements
Recent Announcements

博客园 - 空紫竹

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