日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

配置服务-终结点

發(fā)布時間:2025/6/17 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 配置服务-终结点 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一.終結點

每個終結點包含一個指示可在何處找到此終結點的地址、一個指定客戶端如何與此終結點進行通信的綁定和一個標識可用方法的協定。?

(1).在后臺代碼添加終結點

代碼 ?ServiceHost?host?=?new?ServiceHost(typeof(Fun),?new?Uri?("http://localhost:8285/Service"));
????????????
/*
?????????????*?添加終結點
?????????????
*/
????????????host.AddServiceEndpoint(
typeof(IFun),?new?WSHttpBinding(),"");

?

?

代碼 ?//?摘要:
????????
//?????使用指定的協定、綁定和終結點地址將服務終結點添加到承載服務中。
????????
//
????????
//?參數:
????????
//???implementedContract:
????????
//?????所添加終結點的協定的?System.Type。
????????
//
????????
//???binding:
????????
//?????所添加終結點的?System.ServiceModel.Channels.Binding。
????????
//
????????
//???address:
????????
//?????所添加終結點的地址。
????????
//
????????
//?返回結果:
????????
//?????添加到承載服務中的?System.ServiceModel.Description.ServiceEndpoint。
????????
//
????????
//?異常:
????????
//???System.ArgumentNullException:
????????
//?????implementedContract?或?binding?或?address?為?null。
????????public?ServiceEndpoint?AddServiceEndpoint(Type?implementedContract,?Binding?binding,?string?address);

(2).配置文件

?

代碼 <configuration>
??
<system.serviceModel>
????
<services>
??????
<service?name="UE.Samples.HelloService"
???????????????behaviorConfiguration
="HelloServiceBehavior">
????????
<endpoint?address="/Address1"
??????????????????binding
="basicHttpBinding"?
??????????????????contract
="UE.Samples.IHello"/>

????????
<endpoint?address="mex"
??????????????????binding
="mexHttpBinding"
??????????????????contract
="IMetadataExchange"?/>
??????
</service>
????
</services>
????
<behaviors>
??????
<serviceBehaviors>
????????
<behavior?name="HelloServiceBehavior">
??????????
<serviceMetadata?httpGetEnabled="true"?/>
????????
</behavior>
??????
</serviceBehaviors>
????
</behaviors>
??
</system.serviceModel>
</configuration>

?

?

二.終結點地址的定義
例如,“http://www.fabrikam.com:322/mathservice.svc/secureEndpoint”這個 URI 具有以下四個部分:
方案:http
計算機:www.fabrikam.com
端口:322
路徑/mathservice.svc/SecureEndpoint

?

三.消息標頭

如何在客戶端設置當前上下文中的消息標頭

?

?

代碼 OperationContextScope?scope?=?new?OperationContextScope(wcfClient.InnerChannel)

?MessageHeader?header
??????
=?MessageHeader.CreateHeader(
??????
"Service-Bound-CustomHeader",
??????
"http://Microsoft.WCF.Documentation",
??????
"Custom?Happy?Value."
??????);
????OperationContext.Current.OutgoingMessageHeaders.Add(header);

?

?

?

?

轉載于:https://www.cnblogs.com/tongly/archive/2010/10/18/1854116.html

總結

以上是生活随笔為你收集整理的配置服务-终结点的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。