激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - ASP.NET教程 - .net WCF簡(jiǎn)單實(shí)例詳解(5)

.net WCF簡(jiǎn)單實(shí)例詳解(5)

2020-05-25 14:03清幽火焰 ASP.NET教程

這篇文章主要為大家詳細(xì)介紹了.net WCF簡(jiǎn)單實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文為大家分享了.net WCF簡(jiǎn)單實(shí)例,供大家參考,具體內(nèi)容如下

1.創(chuàng)建WCF項(xiàng)目

.net WCF簡(jiǎn)單實(shí)例詳解(5)

2.系統(tǒng)自動(dòng)生成IWcfService

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// 注意: 使用“重構(gòu)”菜單上的“重命名”命令,可以同時(shí)更改代碼和配置文件中的接口名“IService1”。
  [ServiceContract]
  public interface IWcfService
  {
 
    [OperationContract]
    string GetData(int value);
 
    [OperationContract]
    CompositeType GetDataUsingDataContract(CompositeType composite);
 
    // TODO: 在此添加您的服務(wù)操作
  }
 
 
  // 使用下面示例中說明的數(shù)據(jù)約定將復(fù)合類型添加到服務(wù)操作。
  [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; }
    }
  }

(1)服務(wù)契約:ServiceContract(服務(wù))和OperationContract  (方法)

(2)數(shù)據(jù)契約:DataContract(類)和DataMember(屬性) 用于類和結(jié)構(gòu)上

(3)消息契約:MessageContract 用于soap消息

3.WCF服務(wù)類

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public class WcfService : IWcfService
  {
    public string GetData(int value)
    {
      return string.Format("You entered: {0}", value);
    }
 
    public CompositeType GetDataUsingDataContract(CompositeType composite)
    {
      if (composite == null)
      {
        throw new ArgumentNullException("composite");
      }
      if (composite.BoolValue)
      {
        composite.StringValue += "Suffix";
      }
      return composite;
    }
  }

4.服務(wù)配置文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<system.serviceModel>
  <!--配置綁定節(jié)點(diǎn)Start-->
  <bindings>
   <basicHttpBinding>
    <binding name="basicHttpBinding0" maxReceivedMessageSize="2147483647">
     <readerQuotas maxStringContentLength="2147483647"/>
     <security mode="None" />
    </binding>
   </basicHttpBinding>
   <netTcpBinding>
    <binding name="netTcpBinding0" maxReceivedMessageSize="2147483647">
     <readerQuotas maxStringContentLength="2147483647"/>
     <security mode="None" />
    </binding>
   </netTcpBinding>
   <wsHttpBinding></wsHttpBinding>
  </bindings>
  <!--配置綁定節(jié)點(diǎn)End-->
  
  <!--配置服務(wù)節(jié)點(diǎn)Start-->
  <services>
   <!--配置某一服務(wù),在這里可以指定服務(wù)名稱-->
   <service name="WcfServiceTest.WcfService">
    <endpoint address="aaa" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding0"
     name="BasicHttpBinding_WcfService" contract="WcfServiceTest.IWcfService">
     <identity>
      <dns value="localhost"/>
     </identity>
    </endpoint>
    <endpoint address="" binding="netTcpBinding" bindingConfiguration="netTcpBinding0"
     name="NetTcpBinding_WcfService" contract="WcfServiceTest.IWcfService">
     <identity>
      <dns value="localhost"/>
     </identity>
    </endpoint>
   </service>
  </services>
  <!--配置服務(wù)節(jié)點(diǎn)End-->
 
  <behaviors>
   <serviceBehaviors>
    <behavior>
     <!-- 為避免泄漏元數(shù)據(jù)信息,請(qǐng)?jiān)诓渴鹎皩⒁韵轮翟O(shè)置為 false -->
     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
     <!-- 要接收故障異常詳細(xì)信息以進(jìn)行調(diào)試,請(qǐng)將以下值設(shè)置為 true。在部署前設(shè)置為 false 以避免泄漏異常信息 -->
     <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
   </serviceBehaviors>
  </behaviors>
  <protocolMapping>
    <add binding="basicHttpsBinding" scheme="https" />
  </protocolMapping
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
 </system.serviceModel>

5.iis部署WCF服務(wù)

.net WCF簡(jiǎn)單實(shí)例詳解(5)

.net WCF簡(jiǎn)單實(shí)例詳解(5)

6.添加客戶端項(xiàng)目并添加服務(wù)引用

.net WCF簡(jiǎn)單實(shí)例詳解(5)

7.Main程序中添加wcf服務(wù)并調(diào)用方法

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Program
 {
   static void Main(string[] args)
   {
     var client = new WcfService.WcfServiceClient();
     try
     {
       var str = client.GetData(2046);
       Console.WriteLine(string.Format("內(nèi)容:{0}", str));
       client.Close();
     }
     catch (Exception ex)
     {
       Console.WriteLine("出現(xiàn)異常!");
       client.Abort();
     }
     Console.ReadLine();
   }
 }

8.客戶端配置文件

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_WcfService" />
      </basicHttpBinding>
      <netTcpBinding>
        <binding name="NetTcpBinding_WcfService">
          <security mode="None" />
        </binding>
      </netTcpBinding>
    </bindings>
    <client>
      <!--<endpoint address="http://localhost/WcfServiceTest/WcfService.svc"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_WcfService"
        contract="WcfService.IWcfService" name="BasicHttpBinding_WcfService" />-->
      <endpoint address="net.tcp://localhost/WcfServiceTest/WcfService.svc"
        binding="netTcpBinding" bindingConfiguration="NetTcpBinding_WcfService"
        contract="WcfService.IWcfService" name="NetTcpBinding_WcfService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 成人情欲视频在线看免费 | 成人男女啪啪免费观看网站四虎 | 亚州综合一区 | 午夜精品在线视频 | 亚洲午夜在线观看 | 国产激情视频在线 | 国产精品亚洲一区二区三区在线观看 | 久久久久久久久久综合 | 成人在线免费视频观看 | 成人午夜毛片 | 在线观看日韩中文字幕 | 欧洲成人一区二区 | 亚洲欧美国产高清va在线播放 | 91九色福利| 亚洲国产精品二区 | 一级做人爱c黑人影片 | 欧美人人干 | av免费在线网 | 一级做a爱性色毛片免费1 | 国产成年人网站 | 毛片视频网站在线观看 | 国产美女白浆 | 涩涩屋av | a视频在线免费观看 | 国内精品视频饥渴少妇在线播放 | 激情小视频在线观看 | 黄色成人av在线 | 国产精品久久久久久影院8一贰佰 | 九九热视频在线免费观看 | 性生活视频网站 | 在线 日本 制服 中文 欧美 | 国内久久久久 | 成人国产高清 | 成人免费福利网站 | 国产亚洲精品久久久久久大师 | 伊人一二三四区 | 久久久久久久久久久久久久久伊免 | 欧美日韩国产成人在线观看 | avav在线播放| 国产欧美精品一区二区三区四区 | 久久国产精品久久久久 |