Greetings.
We have some old code in our system and I'm trying to get it to work on a newer platform. We have a C++ 6.0 dll that we call from an old MicroFocus COBOL application. The C++ dll serves as a wrapper to call a .NET web service since we can't call it directly from COBOL. It has been running without any problems on Windows XP, but on Windows Server 2008, I get an error code -2147221164 on the call to CoCreateInstance. I understand this error indicates that the dll is not registered. I never had to register it on the XP machines.
This is the actual code being executed that is throwing the error:
CComPtr<IServerXMLHTTPRequest>spServerXMLHTTP1; HRESULT hr = spServerXMLHTTP1.CoCreateInstance(CLSID_ServerXMLHTTP40); if (hr < 0) { ierror = sprintf(errmsg,"Critical Error CoCreateInstance %+8d",hr); throw (errmsg); }
Here is the code for the entire function:
//------------------------------------------------------------------------------ // Function uses ServerXMLHTTP to send a GET/POST/SOAP request to a .NET Web Services, // and then uses MSXML DOM to process the response XML text. // // Illustrates calling a .NET Web Service either by sending a GET request, // or a HTTP POST or by using the SOAP method. // // iMethod parameter: // 0 : (Default) HTTP GET // 1 : HTTP POST // 2 : SOAP //------------------------------------------------------------------------------ //_bstr_t CallWebService(LPCTSTR szSOAPRequest, LPCTSTR szSOAPAction, LPCTSTR szSOAPEndPoint) //_bstr_t CallWebService(TCHAR * szSOAPRequest, TCHAR * szSOAPAction, TCHAR * szSOAPEndPoint) _bstr_t CallWebService(TCHAR * szSOAPRequest, TCHAR * szSOAPAction, TCHAR * szSOAPEndPoint, int iMethod) { try { char errmsg [100] = {0}; int ierror; _bstr_t bstrRequest; bstrRequest = ConvertStringToBSTR(szSOAPRequest); //iMethod = 0 uses HTTP GET // int iMethod=0; //iMethod = 2 uses SOAP. // int iMethod=2; LPCTSTR szZipCode=""; USES_CONVERSION; // Create an instance of ServerXMLHTTP Class CComPtr<IServerXMLHTTPRequest>spServerXMLHTTP1; HRESULT hr = spServerXMLHTTP1.CoCreateInstance(CLSID_ServerXMLHTTP40); if (hr < 0) { ierror = sprintf(errmsg,"Critical Error CoCreateInstance %+8d",hr); throw (errmsg); } TCHAR szGetURL[MAX_PATH*2]={0}; TCHAR szPostValue[MAX_PATH*2]={0}; TCHAR szSOAPReq[MAX_PATH*2]={0}; int iPostDataLen =0; TCHAR szDataLen[10]={0}; switch(iMethod) { case 0: // HTTP GET sprintf(szGetURL, szSOAPRequest); // Initialize the Synchronous HTTP GET request hr = spServerXMLHTTP1->open(_bstr_t(_T("GET")), szGetURL, VARIANT_FALSE); if (hr < 0) { ierror = sprintf(errmsg,"Critical Error spServerXMLHTTP1->open %+8d",hr); throw (errmsg); } // Send the HTTP GET request hr = spServerXMLHTTP1->send(); if (hr < 0) { ierror = sprintf(errmsg,"Critical Error spServerXMLHTTP1->send %+8d",hr); throw (errmsg); } break; case 1: // HTTP POST _tcscpy(szPostValue, _T("connectionid=")); _tcscat(szPostValue, szZipCode); iPostDataLen = _tcslen(szPostValue); itoa(iPostDataLen, szDataLen, 10); // Initialize the Synchronous HTTP GET request hr = spServerXMLHTTP1->open(_bstr_t(_T("POST")), g_lpszPostURL, VARIANT_FALSE); if (hr < 0) { ierror = sprintf(errmsg,"Critical Error spServerXMLHTTP1->open %+8d",hr); throw (errmsg); } spServerXMLHTTP1->setRequestHeader(_T("Content-Type"), _T("application/x-www-form-urlencoded")); spServerXMLHTTP1->setRequestHeader(_T("Content-Length"), szDataLen); // Send the HTTP POST request, along with the SOAP request envelope text hr = spServerXMLHTTP1->send(szPostValue); if (hr < 0) { ierror = sprintf(errmsg,"Critical Error spServerXMLHTTP1->send %+8d",hr); throw (errmsg); } break; case 2: // SOAP //sprintf(szSOAPReq, g_lpszSOAPReq, szZipCode); hr = spServerXMLHTTP1->open(_bstr_t(_T("POST")), szSOAPEndPoint, VARIANT_FALSE); if (hr < 0) { ierror = sprintf(errmsg,"Critical Error spServerXMLHTTP1->open %+8d",hr); throw (errmsg); } // Set the required SOAPAction and Content-Type headers hr = spServerXMLHTTP1->setRequestHeader(_T("SOAPAction"), szSOAPAction); if (hr < 0) { ierror = sprintf(errmsg,"Critical Error spServerXMLHTTP1->setRequestHeader 1 %+8d",hr); throw (errmsg); } hr = spServerXMLHTTP1->setRequestHeader(_bstr_t(_T("Content-Type")), _bstr_t(_T("text/xml"))); if (hr < 0) { ierror = sprintf(errmsg,"Critical Error spServerXMLHTTP1->setRequestHeader 2 %+8d",hr); throw (errmsg); } // Send the POST request, along with the SOAP request envelope text MSXML2::_SERVERXMLHTTP_OPTION srvval = SXH_OPTION_IGNORE_SERVER_SSL_CERT_ERROR_FLAGS; // MSXML2::_SXH_SERVER_CERT_OPTION valopt = SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS; _variant_t srvopt = spServerXMLHTTP1->getOption(srvval); // MSXML2::_SXH_SERVER_CERT_OPTION srvopt = SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS; spServerXMLHTTP1->setOption(srvval, srvopt); hr = spServerXMLHTTP1->send (bstrRequest); if (hr < 0) { ierror = sprintf(errmsg,"Critical Error spServerXMLHTTP1->send %+8d",hr); throw (errmsg); } break; } if(200 == spServerXMLHTTP1->status) //Success { // using MSXML DOM to process the response XML text CComQIPtr <IXMLDOMDocument2> spResponseXMLDoc; _bstr_t svcresp(spServerXMLHTTP1->GetresponseText()); spResponseXMLDoc = spServerXMLHTTP1->responseXML; return svcresp; } else { _bstr_t svcresp(W2A(spServerXMLHTTP1->statusText)); return svcresp; } } catch (char * errmsg) { _bstr_t svcresp (errmsg); return svcresp; } catch (_bstr_t bstrerr) { int ierror; char errmsg [100] = {0}; ierror = sprintf(errmsg,"Critical Error trying to execute IG Web Service???"); _bstr_t svcresp (errmsg); return svcresp; } catch(_com_error e) { int templen; char errmsg [1000] = "Critical Error - COM "; _bstr_t bstrErrMsg; bstrErrMsg = ConvertStringToBSTR (e.ErrorMessage()); templen = strlen((char *)bstrErrMsg) + 1; memmove(errmsg + 21,(char *) bstrErrMsg, templen); // ierror = sprintf(errmsg,"Critical Error - COM Error trying to execute IG Web Service???"); _bstr_t svcresp (errmsg); return svcresp; } catch (unsigned int e) { int ierror; char errmsg [100] = {0}; if (e == EXCEPTION_INT_DIVIDE_BY_ZERO) { ierror = sprintf(errmsg,"Divide by zero Error trying to execute IG Web Service???"); _bstr_t svcresp (errmsg); return svcresp; } if (e == EXCEPTION_ACCESS_VIOLATION) { ierror = sprintf(errmsg,"Access Violation C++ proxy Error"); _bstr_t svcresp (errmsg); return svcresp; } if (e == EXCEPTION_PRIV_INSTRUCTION) { ierror = sprintf(errmsg,"Attempt to execute privileged instruction proxy Error"); _bstr_t svcresp (errmsg); return svcresp; } if (e == EXCEPTION_STACK_OVERFLOW) { ierror = sprintf(errmsg,"Stack Overflow proxy Error"); _bstr_t svcresp (errmsg); return svcresp; } if (e == EXCEPTION_INT_OVERFLOW) { ierror = sprintf(errmsg,"Integer Overflow proxy Error"); _bstr_t svcresp (errmsg); return svcresp; } ierror = sprintf(errmsg,"Critical Error trying to execute IG Web Service???"); _bstr_t svcresp (errmsg); return svcresp; } catch (std::exception& e) { int templen; char errmsg [1000] = "Critical Error - COM "; _bstr_t bstrErrMsg; bstrErrMsg = ConvertStringToBSTR (e.what()); templen = strlen((char *)bstrErrMsg) + 1; memmove(errmsg + 21,(char *) bstrErrMsg, templen); _bstr_t svcresp (errmsg); return svcresp; } catch(...) { //TODO: Error handling int ierror; // double dwTarget; char errmsg [100] = {0}; // dwTarget = AFX_STACK_DUMP_TARGET_CLIPBOARD // AfxDumpStack(dwTarget); ierror = sprintf(errmsg,"Critical Error trying to execute IG Web Service???"); _bstr_t svcresp (errmsg); return svcresp; } }
Any clues?