• 大小: 0.08M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2020-12-26
  • 语言: C#
  • 标签: jQuery  WCF  jsonp  

资源简介

【注意事项】

我们通过控制台程序对服务进行寄宿。从下面的配置可以看到我们采用了标准终结点WebHttpEndpoint。为了让服务具有跨域支持的能力,我们必须将标准终结点的crossDomainScriptAccessEnabled属性设置为True。WebHttpBinding也具有同名的属性,如果直接使用WebHttpBinding也需要将该属性设置为True。

如下是app.config

 

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <standardEndpoints>
      <webHttpEndpoint>
        <standardEndpoint crossDomainScriptAccessEnabled="true"/>
      </webHttpEndpoint>
    </standardEndpoints>
    <bindings>
      <webHttpBinding>
        <binding crossDomainScriptAccessEnabled="true" />
      </webHttpBinding>
    </bindings>
    <services>      
      <service name="Artech.WcfServices.Service.EmployeesService">
        <endpoint kind="webHttpEndpoint" 
                  address="http://127.0.0.1:3721/employees"
                  contract="Artech.WcfServices.Service.Interface.IEmployees"/>
      </service>
    </services>
  </system.serviceModel>
</configuration>


资源截图

代码片段和文件信息

using System.Collections.Generic;
using Artech.WcfServices.Service.Interface;
namespace Artech.WcfServices.Service
{
    public class EmployeesService : IEmployees
    {
        public IEnumerable GetAll()
        {
            return new List
            {
                new Employee{ Id = “001“ Name=“张三“ Department=“开发部“ Grade = “G6“}    
                new Employee{ Id = “002“ Name=“李四“ Department=“人事部“ Grade = “G7“} 
                new Employee{ Id = “003“ Name=“王五“ Department=“销售部“ Grade = “G8“}
            };
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        744  2012-01-16 20:40  WcfServices\Service\app.config

     文件        621  2012-01-16 21:12  WcfServices\Service\EmployeesService.cs

     文件        515  2012-01-16 20:35  WcfServices\Service\Program.cs

     文件       1426  2012-01-15 12:09  WcfServices\Service\Properties\AssemblyInfo.cs

     文件       2899  2012-01-16 09:18  WcfServices\Service\Service.csproj

     文件        560  2012-01-16 21:12  WcfServices\Service.Interface\IEmployees.cs

     文件       1446  2012-01-15 11:59  WcfServices\Service.Interface\Properties\AssemblyInfo.cs

     文件       2524  2012-01-16 09:18  WcfServices\Service.Interface\Service.Interface.csproj

     文件       3613  2012-01-16 10:49  WcfServices\WcfServices.sln

    ..A..H.     58880  2012-01-16 21:15  WcfServices\WcfServices.suo

     文件       2011  2012-01-16 21:12  WcfServices\WebUI\Default.html

     文件       1381  2012-01-16 10:41  WcfServices\WebUI\Properties\AssemblyInfo.cs

     文件     338582  2012-01-16 11:39  WcfServices\WebUI\scripts\jquery-1.7.1.js

     文件       3948  2012-01-16 21:14  WcfServices\WebUI\WebUI.csproj

     文件       1171  2012-01-16 21:14  WcfServices\WebUI\WebUI.csproj.user

     目录          0  2012-01-16 09:21  WcfServices\Service\Properties

     目录          0  2012-01-16 09:21  WcfServices\Service.Interface\Properties

     目录          0  2012-01-16 10:41  WcfServices\WebUI\Properties

     目录          0  2012-01-16 20:34  WcfServices\WebUI\scripts

     目录          0  2012-01-16 21:15  WcfServices\Service

     目录          0  2012-01-16 21:15  WcfServices\Service.Interface

     目录          0  2012-01-16 21:15  WcfServices\WebUI

     目录          0  2012-01-16 21:13  WcfServices

----------- ---------  ---------- -----  ----

               420321                    23


评论

共有 条评论