“endpoint is a duplicate” when starting an RPC server

淺唱寂寞╮ 提交于 2019-12-11 01:56:25

问题


My program uses Microsoft RPC for interprocess communications. To prepare for receiving RPC calls the program runs the following sequence:

  1. RpcServerUseProtseqEp(), then

  2. RpcServerRegisterIf(), then

  3. RpcServerListen()

The program starts its RPC server with the sequence above, works for some time, then terminates and may later be restarted by another program. The set of parameters values for RpcServerUseProtseqEp() is the same each time the program is run.

When the sequence is run the first time after reboot it always succeeds, but on subsequent runs RpcServerUseProtseqEp() returns RPC_S_DUPLICATE_ENDPOINT ("The endpoint is a duplicate.") Currently I just ignore this particular error code and treat it as success, then all the other primitives usually work fine.

What is the correct way of using RpcServerUseProtseqEp()? Should I do any cleanup to revoke the registered endpoint or just keep ignoring the RPC_S_DUPLICATE_ENDPOINT error code?


回答1:


i had the same problem, i can't fixed totally, but this code works for me:

UCHAR* pszProtocolSequence = (UCHAR*)"ncacn_ip_tcp"; // Use RPC over TCP/IP
UCHAR* pszSecurity = NULL;
UCHAR* pszEndpoint = (UCHAR*)"9300";
UINT cMinCalls = 1;
UINT cMaxCalls = m_dwConcurrentChannels;
UINT fDontWait = FALSE;

int RPC_tries, MAX_RPC_Tries;
RPC_tries=0;
MAX_RPC_Tries=60;
do
{
    status = ::RpcServerUseProtseqEp(
    pszProtocolSequence, cMaxCalls, pszEndpoint, pszSecurity);
    Sleep(1000);
    RPC_tries+=1;
}while(status!=RPC_S_OK && RPC_tries<MAX_RPC_Tries);

For some reason you have to wait some time until use RpcServerUseProtseqEp again when you restart a windows service.




回答2:


I'm not an expert on RPC, but I think you may want to unregister your endpoint using RpcEpUnregister when your server terminates. The docs for this function mention an endpoint database which I guess is persisting across instatiations of your server.



来源:https://stackoverflow.com/questions/746702/endpoint-is-a-duplicate-when-starting-an-rpc-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!