国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Step by Step 創建一個WCF Service

2019-11-17 01:48:41
字體:
來源:轉載
供稿:網友

Step by Step 創建一個WCF Service

原創地址:http://m.survivalescaperooms.com/jfzhu/p/4025448.html

轉載請注明出處

(一)創建WCF Service

(1)創建WCF Service類庫

創建一個Class Library的項目:

image

刪除掉默認的Class1.cs文件,然后添加一個WCF Service項目:

image

Visual Studio會自動幫助你生成兩個文件:HelloService.cs 和 IHelloService.cs,另外還自動添加了System.ServiceModel引用,它是WCF的核心。

image

修改IHelloService.cs和HelloService.cs文件。

IHelloService.cs:

namespace HelloService{    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IHelloService" in both code and config file together.    [ServiceContract]    public interface IHelloService    {        [OperationContract]        string GetMessage(string name);    }}

HelloService.cs:

namespace HelloService{    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "HelloService" in both code and config file together.    public class HelloService : IHelloService    {        public string GetMessage(string name)        {            return "Hello " + name;        }    }}

(2)創建WCF的Host

添加一個新的asp.net Empty Web application

image

添加一個新Item WCF Service

image

image

刪除HelloService.svc.cs和IHelloService.cs文件。

添加HelloService Class Library的項目引用:

image

修改HelloService.svc為:

<%@ ServiceHost Language="C#" Debug="true" Service="HelloService.HelloService" %>

Web.config:

<?xml version="1.0" encoding="utf-8" ?><configuration>  <system.serviceModel>    <services>      <service name="HelloService.HelloService" behaviorConfiguration="metaBehavior">        <endpoint address="HelloService" binding="basicHttpBinding" contract="HelloService.IHelloService"></endpoint>        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>        <host>          <baseAddresses>            <add baseAddress="http://localhost:8080"/>          </baseAddresses>        </host>      </service>    </services>    <behaviors>      <serviceBehaviors>        <behavior name="metaBehavior">          <serviceMetadata httpGetEnabled="true"/>        </behavior>      </serviceBehaviors>    </behaviors>  </system.serviceModel></configuration>

其中,service name=”命名空間.類名”,behaviorConfiguration是用來關聯下面behavior的定義的。

endpoint address中定義的是相對地址,與baseAddress結合起來為完整地址

endpoint contract=”命名空間.接口名”

兩個endpoint,第一個binding是basicHttpBinding,用于HTTP協議;第二個endpoint用于交換metadata,binding為mexHttpBinding。

其中behavior的定義是用來允許交換metadata的。

Build解決方案,如果沒有錯誤就進行到下一步,部署WCF Service到IIS

(二)部署WCF Service到IIS

(1)Publish HelloServiceIISHost項目

image

image

image

image

image

image

(2)部署到IIS

image

image

image

瀏覽HelloService.svc

image

image

(三)創建一個Windows Form來調用WCF Service

image

添加一個服務引用:

image

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东台市| 博湖县| 永宁县| 霍州市| 友谊县| 安西县| 思南县| 鄱阳县| 洮南市| 称多县| 肃宁县| 玛纳斯县| 多伦县| 密山市| 乡宁县| 通州区| 梨树县| 逊克县| 陕西省| 台中市| 迁西县| 太保市| 华池县| 老河口市| 城口县| 清涧县| 安庆市| 思南县| 漠河县| 乌什县| 赤峰市| 青岛市| 临清市| 闸北区| 万年县| 闵行区| 祥云县| 榆林市| 土默特右旗| 本溪市| 兴安县|