• 配置服务终结点


    一.终结点

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

    (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);
  • 相关阅读:
    python中修改元组
    c语言中语音警告转义字符
    linux中防火墙策略管理工具firewalld
    C语言获取数值的最后几位数
    VMware安装win7虚拟机
    python中字符串的常规处理
    专家详解面试成功法宝和技巧
    怎样学好java
    一个Java程序员应该掌握的10项技能
    专家详解面试成功法宝和技巧
  • 原文地址:https://www.cnblogs.com/tongly/p/1854116.html
Copyright © 2020-2023  润新知