Thrift源码修改,改造RPC,支持多Processor模式(C#客户端调用)

来源:互联网 发布:java accept 编辑:程序博客网 时间:2024/05/19 22:24

之前对thrift服务端java版本的源码进行改造,使支持多服务接口的加载,具体请参考:http://blog.csdn.net/yefeng_918/article/details/7707541

 

由于客户端需要使用C#和java,现在对C#版客户端调用源码进行修改,使适应改版后的服务端。主要修改TBinaryProtocol类得WriteMessageBegin方法(阻塞调用模式,非阻塞没做修改,原理同java版),具体修改代码如下。

 

 

public override void WriteMessageBegin(TMessage message)
  {
            // 处理服务调用类
            StackTrace st = new StackTrace();
            StackFrame sf = st.GetFrame(1);
            String className = sf.GetMethod().ReflectedType.FullName;
            String servieName = (className.Split('+'))[0] + "_" + message.Name;

   if (strictWrite_)
   {
    uint version = VERSION_1 | (uint)(message.Type);
    WriteI32((int)version);
                WriteString(servieName);    // 设置修改后的服务名
    WriteI32(message.SeqID);
   }
   else
   {
                WriteString(servieName);    // 设置修改后的服务名
    WriteByte((byte)message.Type);
    WriteI32(message.SeqID);
   }
  }