資源簡介
【注意事項】
我們通過控制臺程序對服務進行寄宿。從下面的配置可以看到我們采用了標準終結點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\sc
?????文件???????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\sc
?????目錄??????????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
評論
共有 條評論