日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

WCF入门(五)---创建WCF服务

發(fā)布時間:2023/12/20 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WCF入门(五)---创建WCF服务 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

使用Microsoft Visual Studio2012創(chuàng)建WCF服務(wù),理解如下所有必要的編碼,更好地創(chuàng)建WCF服務(wù)的概念,這里做一個簡單的任務(wù)。

  • 啟動Visual Studio 2012。

  • 單擊新建項(xiàng)目,然后在Visual C#標(biāo)簽,選擇WCF選項(xiàng)。

WCF服務(wù)創(chuàng)建,執(zhí)行如加法,減法,乘法和除法基本的算術(shù)運(yùn)算。主要的代碼是在兩個不同的文件 - 一個接口和一個類。

一個WCF中包含一個或多個接口和實(shí)現(xiàn)類。

using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.Text; namespace WcfServiceLibrary1 { //NOTE: You can use the "Rename" command on the "Refactor" menu to change the //interface name "IService1" in both code and config file together. [ServiceContract] Public interface IService1 { [OperationContract] int sum(int num1, int num2); [OperationContract] int Subtract(int num1, int num2); [OperationContract] int Multiply(int num1, int num2); [OperationContract] int Divide(int num1, int num2); } //Use a data contract as illustrated in the sample below to add composite types //to service operations. [DataContract] Public class CompositeType { Bool boolValue = true; String stringValue = "Hello "; [DataMember] Public bool BoolValue { get { return boolValue; } set { boolValue = value; } } [DataMember] Public string StringValue { get { return stringValue; } set { stringValue = value; } } } }

而其后面是類的代碼,

using System; usingSystem.Collections.Generic; usingSystem.Linq; usingSystem.Runtime.Serialization; usingSystem.ServiceModel; usingSystem.Text; namespace WcfServiceLibrary1 { //NOTE: You can use the "Rename" command on the "Refactor" menu to change the //class name "Service1" in both code and config file together. publicclassService1 :IService1 { /// This Function Return summation of two integer numbers publicint sum(int num1, int num2) { return num1 + num2; } ///This function returns subtraction of two numbers. ///If num1 is smaller than number two then this function returns 0. publicint Subtract(int num1, int num2) { if (num1 > num2) { return num1 - num2; } else { return 0; } } ///This function returns multiplication of two integer numbers. publicint Multiply(int num1, int num2) { return num1 * num2; } ///This function returns integer value of two integer number. ///If num2 is 0 then this function returns 1. publicintDivide(int num1, int num2) { if (num2 != 0) { return (num1 / num2); } else { return 1; } } } }

要運(yùn)行此服務(wù),請?jiān)赩isual Studio中點(diǎn)擊開始按鈕。

當(dāng)我們運(yùn)行這個服務(wù),下面的屏幕會出現(xiàn)。

上點(diǎn)擊sum方法,在下面的頁面將被打開。在這里,可以輸入任何兩個整數(shù),然后單擊Invoke按鈕。該服務(wù)將返回這兩個數(shù)字的總和。

?

像求和,我們可以執(zhí)行哪個都列在菜單中的所有算術(shù)運(yùn)算。這里是捕捉他們。

當(dāng)點(diǎn)擊下頁將出現(xiàn)在Sutbtarct方法。輸入整數(shù),點(diǎn)擊調(diào)用按鈕,得到的輸出如下所示。

下頁將出現(xiàn)在Multiply方法單擊時。輸入整數(shù),點(diǎn)擊調(diào)用按鈕,得到的輸出如下所示。

下面的頁面上會出現(xiàn)當(dāng)點(diǎn)擊Divide方法時。輸入整數(shù),點(diǎn)擊調(diào)用按鈕,得到的輸出如下所示。

一旦服務(wù)被調(diào)用,可以在它們之間,直接從這里切換。

原文地址:http://www.yiibai.com/wcf/wcf_creating_services.html

轉(zhuǎn)載于:https://www.cnblogs.com/CSharpLover/p/5687263.html

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的WCF入门(五)---创建WCF服务的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。