关于RPC方式的C/S程序测试-01

环境:VC++6.0

1.首先利用uuidgen.exe /i /Rpc.idl命令生成一个Rpc.idl文件(文件名字自己取,但必须是.idl类型)。

生成文件内容格式如下

[
uuid(abb12775-f053-4c62-95c2-4d9bc7fdbfef),
version(1.0)
]
interface INTERFACENAME
{

}

2.在 interface INTERFACENAME 的括号内写入你在服务器端要调用的函数。

比如:(下列代码来自:http://www.codeproject.com/KB/IP/rpcintro2.aspx

// File ContextExample.idl
[
   // A unique identifier that distinguishes this interface from other interfaces.
   uuid(00000003-EAF3-4A7A-A0F2-BCE4C30DA77E),

   // This is version 1.0 of this interface.
   version(1.0)
]
interface ContextExample // The interface is named ContextExample
{
   // To fully use context handles we need to do a typedef.
   typedef [context_handle] void* CONTEXT_HANDLE;

   // Open a context on the server.
   CONTEXT_HANDLE Open(
      // Explicit server binding handle.
      [in] handle_t hBinding,
      // String to be output on the server.
      [in, string] const char* szString);

   // Output the context string on the server.
   void Output(
      // Context handle. The binding handle is implicitly
      // used through the explicit context handle.
      [in] CONTEXT_HANDLE hContext);

   // Closes a context on the server.
   void Close(
      // Context handle. The binding handle is implicitly
      // used through the explicit context handle.
      [in, out] CONTEXT_HANDLE* phContext);
}

3.对生成的.idl文件执行 MIDL.EXE ContextExample.idl(文件名根据你的自己文件名而定)

   这样会生成:ContextExample.h ContextExample_s.c ContextExample_c.c 3个文件。

4.生成2个工程,一个是服务器端,一个是客户端。

   将ContextExample.idl ContextExample.h ContextExample_s.c 导入服务器端工程;

   将ContextExample.idl ContextExample.h ContextExample_c.c 导入客户端工程。

5.在服务器端编写被调用函数的实现代码,在客户端编写调用代码就可以进行RPC方式的C/S程序的测试。

不过这种方式和直接使用Socket或CSocket哪个更适合某些实际的应用,还待试验!

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值