配置服务-终结点

一.终结点

每个终结点包含一个指示可在何处找到此终结点的地址、一个指定客户端如何与此终结点进行通信的绑定和一个标识可用方法的协定。 

(1).在后台代码添加终结点

ExpandedBlockStart.gif 代码
 ServiceHost host  =   new  ServiceHost( typeof (Fun),  new  Uri ( " http://localhost:8285/Service " ));
            
/*
             * 添加终结点
             
*/
            host.AddServiceEndpoint(
typeof (IFun),  new  WSHttpBinding(), "" );

 

 

ExpandedBlockStart.gif 代码
  //  摘要:
        
//      使用指定的协定、绑定和终结点地址将服务终结点添加到承载服务中。
        
//
        
//  参数:
        
//    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).配置文件

 

ExpandedBlockStart.gif 代码
< 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

 

三.消息标头

如何在客户端设置当前上下文中的消息标头

 

 

ExpandedBlockStart.gif 代码
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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值