zoukankan      html  css  js  c++  java
  • 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>
    
  • 相关阅读:
    进程间通信
    图形的保存与重绘
    mysql记录1
    文件操作
    多线程及聊天室程序
    健康是成功之本
    文档与串行化
    HTML网页制作基础
    Hook和数据库访问
    C++基础笔记1
  • 原文地址:https://www.cnblogs.com/objectboy/p/3077870.html
Copyright © 2011-2022 走看看