配置服务-终结点
一.終結點
每個終結點包含一個指示可在何處找到此終結點的地址、一個指定客戶端如何與此終結點進行通信的綁定和一個標識可用方法的協定。?
(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
總結
- 上一篇: BinaryTreeTraversal(
- 下一篇: 完全搞懂傅里叶变换和小波(3)——泰勒公