WCF

1.接口定义需要ServiceContract注解

内部函数要用OperationContract注解

/// <summary>
/// 服务定义
/// </summary>
[ServiceContract(Namespace = "http://www.xxxx.com")]
[System.Web.Script.Services.ScriptService]
public interface IXPAPSWebService
{
[OperationContract]
ExecResult XPAPSInvoker(DataStruct data);
}/// <summary>
/// 服务入口
/// </summary>
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, Namespace = "http://www.xxxx.com")]
[System.Web.Script.Services.ScriptService]
public class ServicePoint : IXPAPSWebService

2.启动和关闭

string tempUri = string.Format("http://{0}:{1}/xxws", ip, port);
Uri uri = new Uri(tempUri);
//创建宿主
serviceHost = new ServiceHost(typeof(ServicePoint), uri);
//自动加载config
serviceHost.Open();
serviceHost.Close();

3.绑定方式

basicHttpBinding http和soap协议 类似wbeservice

http://{0}:{1}/xxws

netTcpBinding tcp通信和字节流,性能要好

net.tcp://localhost:19200/HomeService

netMsmqBinding

 msmqbinding中是不可以让契约方法有返回值的。所以我们加上isoneway就好

using System.Runtime.Serialization;
using System.ServiceModel;

namespace MyService
{
    [ServiceContract]
    public interface IHomeService
    {
        [OperationContract(IsOneWay = true)]
        void GetLength(string name);
    }
}
net.msmq://localhost/private/homequeue
4. 单向模式和双向模式
http适合单向Operation(IsOneWay=true)
tcp 适合双向和单向

 

posted @ 2020-07-28 16:12  lldbang  阅读(121)  评论(0)    收藏  举报