Типы протоколов WSDescovery с WSD_NAME_LIST получают NULL в обслуживании - PullRequest
0 голосов
/ 30 ноября 2018

Я пытаюсь создать службу wsd для обнаружения клиентом WSD.Я следую коду с открытым исходным кодом из примера обнаружения веб-службы ( WS-Discovery ) и внес небольшое изменение в код TargetService.cpp , чтобы получить WSD_NAME_LIST * m_typesList;который не закодирован в примере.

_Success_(return == S_OK)
HRESULT _GenerateTypesList(_In_ LPWSTR epr, _Outptr_ WSD_NAME_LIST ** xTypesList)
{
    HRESULT hr = S_OK;
    WSD_NAME_LIST *tempTypesList = NULL;
    WSDXML_NAME* tempName = NULL;
    WSDXML_NAMESPACE* tempSpace = NULL;
    LPWSTR tempType = NULL;
    size_t length = 0;
    tempTypesList = (WSD_NAME_LIST *)WSDAllocateLinkedMemory(NULL, sizeof(WSD_NAME_LIST));
    if (NULL == tempTypesList)
    {
        hr = E_OUTOFMEMORY;
    }
    else
    {
        tempTypesList->Element = NULL;
        tempTypesList->Next = NULL;
    }

    if (S_OK == hr)
    {
        length = sizeof(WCHAR) * (wcslen(L"wsdp") + 1) *2;
        tempType = (LPWSTR)WSDAllocateLinkedMemory(tempTypesList, length);
        if (NULL == tempType)
        {
            hr = E_OUTOFMEMORY;
        }
    }

    if (S_OK == hr)
    {
        // create the types prefix string
        hr = StringCchPrintfW(tempType, length, L"%s", L"wsdp");
    }

    if (S_OK == hr)
    {
        tempSpace = (WSDXML_NAMESPACE*)WSDAllocateLinkedMemory(tempTypesList, sizeof(WSDXML_NAMESPACE) + length);
        if (NULL == tempSpace)
        {
            hr = E_OUTOFMEMORY;
        }
    }

    if (S_OK == hr)
    {
        tempSpace->PreferredPrefix = tempType;
    }

    if (NULL != tempType)
    {
        WSDFreeLinkedMemory(tempType);
        tempType = NULL;
    }

    if (S_OK == hr)
    {
        length = sizeof(WCHAR) * (wcslen(L"Device") + 1)*2;
        tempType = (LPWSTR)WSDAllocateLinkedMemory(tempTypesList, length);
        if (NULL == tempType)
        {
            hr = E_OUTOFMEMORY;
        }
    }

    if (S_OK == hr)
    {
        // create the XAddrs string
        hr = StringCchPrintfW(tempType, length, L"%s", L"Device");
    }

    if (S_OK == hr)
    {
        tempName = (WSDXML_NAME*)WSDAllocateLinkedMemory(tempTypesList, sizeof(WSDXML_NAME)+length);
        if (NULL == tempName)
        {
            hr = E_OUTOFMEMORY;
        }
    }

    if (S_OK == hr)
    {
        // the xaddrs list now owns the xaddrs string
        tempName->Space = tempSpace;
        tempName->LocalName = tempType;
        tempTypesList->Element = tempName;
        tempType = NULL;
        // outside pointer now owns the list
        *xTypesList = tempTypesList;
        tempTypesList = NULL;
    }

    if (NULL != tempType)
    {
        WSDFreeLinkedMemory(tempType);
        tempType = NULL;
    }

    if (NULL != tempName)
    {
        WSDFreeLinkedMemory(tempName);
        tempName = NULL;
    }

    if (NULL != tempTypesList)
    {
        WSDFreeLinkedMemory(tempTypesList);
        tempTypesList = NULL;
    }

    return hr;
}

и для вызова вышеупомянутого метода в переписанной функции инициализации - это тот же файл, я включил следующий код

WSD_NAME_LIST *tempTypesList = NULL;
if (S_OK == hr)
{
    // Generate TypesList
    hr = _GenerateTypesList(tempEpr, &tempTypesList);
}
m_typesList = tempTypesList;

Теперь я могу сгенерироватьмой список типов, но после выполнения следующей строки кода значение m_typesList становится равным NULL

// Registering the notification sink starts the publisher
// (it will begin to listen to Probe and Resolve messages).
hr = m_publisher->RegisterNotificationSink(
     static_cast<IWSDiscoveryPublisherNotify *>( this )
);

что я пропускаю в этом?

...