Platform SDK: Active Directory, ADSI, and Directory Services |
The following C++ code fragment is called by a service installation program to publish an RPC service:
status = RpcServerUseProtseq((TCHAR *)TEXT("ncacn_ip_tcp"), RPC_C_PROTSEQ_MAX_REQS_DEFAULT, NULL); //Register our interface with the RPC run time. status = RpcServerRegisterIf(RpcExample_v1_0_s_ifspec,NULL,NULL); //Collect the bindings provided by the RPC run time. status = RpcServerInqBindings(&pBindingVec); //Clear the endpoints out of the binding handles. //This forces the clients through the Endpoint Mapper and //reduces the volatility of the namespace entry for this //service. for (i=0; i < pBindingVec->Count; ++i) { RpcBindingReset(pBindingVec->BindingH[i]); } //Create the entry in the name service for this service. status = RpcNsBindingExport(RPC_C_NS_SYNTAX_DEFAULT, (TCHAR *)&szEntryName, RpcExample_v1_0_s_ifspec, pBindingVec, NULL);
The following code is called by the service when it starts up to register with the endpoint mapper.
//Use TCP/IP as the protocol: max concurrent users 64, //no NT Security Descriptor. status = RpcServerUseProtseq((TCHAR *)TEXT("ncacn_ip_tcp"), RPC_C_PROTSEQ_MAX_REQS_DEFAULT, NULL); //Register our interface with the RPC run time. status = RpcServerRegisterIf(RpcExample_v1_0_s_ifspec,NULL,NULL); //Collect the bindings provided by the RPC run time. status = RpcServerInqBindings(&pBindingVec); //Register the interface with the Endpoint Mapper. //There are no Object UUIDs or Annotation string in this example. status = RpcEpRegister(RpcExample_v1_0_s_ifspec, pBindingVec,NULL,NULL); //Start the server. When RpcServerListen returns, the server is //shutting down. if (status != RPC_S_OK) return; //Handle calls from clients until we are shut down. status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, 0); //Remove this service from the endpoint map. We need to get a //new binding vector since the old one has the endpoints removed //and does not match what we registered. // //RpcBindingVectorFree(&pBindingVec); //RpcServerInqBindings(&pBindingVec); status = RpcEpUnregister(RpcExample_v1_0_s_ifspec,pBindingVec, NULL);