• wcf实现可靠性传输


    绑定协议名称                     支持可靠性       默认可靠性    支持有序传递       默认有序传递
    
    BasicHttpBinding                No             N/A          No               N/A
    
    NetTcpBinding                   Yes            Off          Yes              On
    
    NetPeerTcpBinding               No             N/A          No               N/A
    
    NetNamedPipeBinding             No             N/A (On)     Yes              N/A (On)
    
    WSHttpBinding                   Yes            Off          Yes              On
    
    WSFederationHttpBinding         Yes            Off          Yes              On
    
    WSDualHttpBinding               Yes            On           Yes              On
    
    NetMsmqBinding                  No             N/A          No               N/A
    
    MsmqIntegrationBinding          No             N/A          No               N/A
    

    首先添加一个wcf应用程序:

    using System.ServiceModel;
    
    namespace WcfService1
    {
    	[ServiceContract]
    	public interface IGeneralCalculator
    	{
    		[OperationContract]
    		double Add(double x, double y);
    	}
    }
    
    namespace WcfService1
    {    
        public class GeneralCalculator : IGeneralCalculator
        {
            public double Add(double x, double y)
            {
                return x + y;
            }
        }
    }
    

    再添加一个控制台应用程序作为宿主:

    在宿主中使用代码进行配置abc的操作:

    using System;
    using System.ServiceModel;
    using WcfService1;
    
    namespace Hosting
    {
        class Program
        {
            static void Main(string[] args)
            {
                using (ServiceHost host = new ServiceHost(typeof(WcfService1.GeneralCalculator)))
                {
                    host.AddServiceEndpoint(typeof(WcfService1.IGeneralCalculator), new BasicHttpBinding(), "http://localhost:8080/");
                    host.Open();
                    Console.Write("1111111111111111111111");
                    Console.ReadLine();
                }  
            }
        }
    

     当然也可以使用配置的方式实现(在service端),终结点以相对地址写入:

    <services>
          <service name="WcfService1.GeneralCalculator">
            <host>
              <baseAddresses>     
                <add baseAddress="http://localhost:8080"/>
              </baseAddresses>
            </host>   
            <endpoint address="mex" binding="BasicHttpBinding" contract="WcfService1.IGeneralCalculator">
            </endpoint>
          </service>
    </services>
    
  • 相关阅读:
    mongodb 数据库创建用户名密码
    idea代码自动换行
    [ICPC2014 WF] Metal Processing Plant
    [NWRRC2015] Insider's Information
    [CERC2013] Escape
    [ICPC2015 WF] Tours
    AHOI 2022 题目选做
    LNOI 2022 题目选做
    [JOISC 2017 Day1] 开荒者
    [USACO 2020 US Open Platinum] Circus
  • 原文地址:https://www.cnblogs.com/objectboy/p/3077870.html
Copyright © 2020-2023  润新知