zoukankan      html  css  js  c++  java
  • 配置服务终结点

    一.终结点

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

    (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);
  • 相关阅读:
    Cisco IOS XE 3S–to–Cisco IOS Release Number Mapping
    ORA-01157 误删表空间对应的dbf文件出现的错误的解决办法
    记录-Windows10 cnpm报禁止运行脚本
    记录-html和html5区别
    记录-查询硬盘物理序号
    CRC16 Java 实现
    kaldi解码及特征提取详解
    kaldi GMM模型解码指令 gmm-latgen-faster详解
    kaldi基于GMM的单音素模型 训练部分
    kaldi学习
  • 原文地址:https://www.cnblogs.com/tongly/p/1854116.html
Copyright © 2011-2022 走看看