Partager via


How to Invoke a Configuration Manager Management Point Message

Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2

To make a synchronous call to a Microsoft System Center Configuration Manager 2007 endpoint, you use the ISmsMessaging::Invoke Method method. This method takes an XML defined message, and returns, synchronously, an XML blob from a management point endpoint.

The following C++ example shows how to request policy assignments from a management point on the local computer. The example demonstrates how to do the following:

  • Create the message.

  • Set the message body for a policy assignment request. You will need to implement the method CreatePolicyAssignmentsRequestMessage to create the XML that is used by ISmsMessage::SetBodyFromString Method. The memory for the XML must be allocated by using CoTaskMemAlloc. For information about the XML you need to create, see the Configuration Manager Policy Assignment Message XML.

  • Set the target endpoint to the policy manager.

  • Set the management point computer. In this case, null is passed to signify the local computer.

  • Make the synchronous call.

  • Retrieve the returned XML.

  • Clean up after the call. In particular, CoTaskMemFree must be called to free the memory that is used by the input message body XML and the returned XML.

Example

HRESULT RequestPolicyAssignments()
{
    ISmsMessaging               *pMessaging = NULL;
    ISmsMessage                 *pRequest = NULL;
    ISmsMessage                 *pReply = NULL;
    WCHAR                       *pszRequestMessage = NULL;
    WCHAR                       *pszReplyMessage = NULL;

    _BEGIN

        // Create root messaging object.
        _CHECKHR( ::CoCreateInstance(
                        CLSID_SmsMessaging,
                        NULL,
                        CLSCTX_INPROC,
                        IID_ISmsMessaging,
                        (LPVOID*)&pMessaging) );

        // Create message object for the request.
        _CHECKHR( pMessaging->CreateMessage(&pRequest) );

        // Set the target of the message to be the Policy Manager endpoint.
        _CHECKHR( pRequest->SetTargetEndpoint(L"MP_PolicyManager") );

        // Construct a policy assignments request message.
        _CHECKHR( CreatePolicyAssignmentsRequestMessage(&pszRequestMessage) );

        // Set the message body with the request.
        _CHECKHR( pRequest->SetBodyFromString(pszRequestMessage) );

        // Invoke the targeted endpoint on the local computer with the request,
        // and retrieve the reply.
        _CHECKHR( pMessaging->Invoke(NULL, pRequest, &pReply) );

        // Extract body from reply message.
        _CHECKHR( pReply->GetBodyToString(&pszReplyMessage) );

        // Add code to use the reply message.

    _END

    // All cleanup must go after _END block to ensure it gets invoked.

    if(pszReplyMessage)
    {
        ::CoTaskMemFree(pszReplyMessage);
    }

    if(pReply)
    {
        pReply->Release();
    }

    if(pszRequestMessage)
    {
        ::CoTaskMemFree(pszRequestMessage);
    }

    if(pRequest)
    {
        pRequest->Release();
    }

    if(pMessaging)
    {
        pMessaging->Release();
    }

    return _RETVAL;
}

Compiling the Code

Configuration Manager 2007 management point interface DLL.

Security

You can set security options for a message by using ISmsMessage4 Interface. For more information, see Configuration Manager Management Point Interface Security.

See Also

Concepts

About Configuration Manager Management Point Interface Messages
Configuration Manager Management Point Interface
Configuration Manager Management Point Message Schema
ISmsMessage Interface
ISmsMessage2 Interface
ISmsMessage4 Interface
ISmsMessaging Interface