WCF部署于IIS相關(guān)技巧解析
WCF的應用可以幫助我們打造一個安全性極高的解決方案。那么我們?nèi)绾握_使用這一工具呢?在這里我們可以先來了解一下WCF部署于IIS的相關(guān)技巧,以方便我們對此工具的應用技術(shù)有一個深入的了解。#t#
1. 安裝完 VS Extension 后,我們可以創(chuàng)建一個 WCF service 的網(wǎng)站項目。
2. 添加一個 WCF service 新項,系統(tǒng)自動會創(chuàng)建 Service.svc、App_Code\Service.cs 等必要文件。
3. 在 Service.cs 文件中完成服務編碼。
4. 添加 web.config 文件,并在其位置單擊鼠標右鍵,打開 "Microsoft Service Configuration Editor" 工具完成服務配置。
5. 注意添加 serviceMetadata,否則我們使用瀏覽器無法查看,也無法創(chuàng)建客戶端代理。
web.config 演示 (注意配置文件中并沒有提供服務地址)
- < ?xml version="1.0"?>
- < configuration xmlns="http://schemas.microsoft.com/
.NetConfiguration/v2.0">- < system.serviceModel>
- < services>
- < service behaviorConfiguration="MyServiceTypeBehaviors"
name="MyService">- < endpoint binding="wsHttpBinding" contract="IMyService"/>
- < /service>
- < /services>
- < behaviors>
- < serviceBehaviors>
- < behavior name="MyServiceTypeBehaviors">
- < serviceMetadata httpGetEnabled="true"/>
- < serviceDebug includeExceptionDetailInFaults="true"/>
- < /behavior>
- < /serviceBehaviors>
- < /behaviors>
- < /system.serviceModel>
- < system.web>
- < compilation debug="true">
- < /system.web>
- < /configuration>service.svc
- < %@ ServiceHost Language="C#" Debug="true" Service="MyService"
CodeBehind="~/App_Code/service.cs" %>
建議將服務放到一個單獨的 Library 中,這樣更改宿主環(huán)境會更方便一點,不過上述步驟要做些修改。