tags:

views:

523

answers:

2

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?

A: 

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.

anon
Tried to call RpcServerInqBindings(), then RpcEpUnregister(). The former succeeds, the latter returns "the server endpoint failed to perform the operation".
sharptooth
+1  A: 

Hi, 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.

Regards from Peru.

josetg