Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

consuming a .net web service with C++ 6.0

Posted on 2004-08-12
5
Medium Priority
?
535 Views
Last Modified: 2010-05-18
Would prefer details on using SOAP , GET , and POST to retrieve. Not asking for code (but feel  free to submit any code you so desire) just good articles and starting points.
Thanks.
0
Comment
Question by:mccainz2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 11785238
Maybe http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsoap/html/understandsoap.asp ("Understanding SOAP") or http://www.microsoft.com/mind/0100/soap/soap.asp ("SOAP: The Simple Object Access Protocol") is a good point to start.
0
 
LVL 5

Author Comment

by:mccainz2
ID: 11785326
Sorry , wasnt clear.
Issue is how to consume these .net services from a vc++ 6.0 (unmanaged code) client.
I am not a C++ but rather a .net developer and I am trying to facillitate (read convince) a contractor I work with to consume my .net web service rather than relying on our current architecture for data transfer.
0
 
LVL 1

Expert Comment

by:ageraldnaveen
ID: 11785803
instead of writing your own webservices layer on the client side using SOAP,HTTP etc.,

my suggestion is...

u just develop a .Net component wrapper for your webservice.
create a CCW for your .Net component and use it in your client application..

by doing this, u are making reuse of the .Net webservices architecture. you need not write your own coding for webservices layer right?

you shall take this, if you are not very much concerned about the performance..(very much !!)
but this would be an easy solution for your problem.
0
 
LVL 5

Author Comment

by:mccainz2
ID: 11787124
My lack of c++ may be hindering me here but I simply need to know how a remote C++ 6.0 client can call a .net webservice which can respond to either SOAP,GET,or POST (BTW, this will be an https URL for the webservice). All I really need is a good article I can pass to our C++ developer that will  either (1) allow me to write a simple C++ app so as to shame him into using my webservice or (2) get him started on the correct path by showing him it is possible.

Thanks, and forgive my lack of Knowledge regarding the client side of calling webservices , especially from VC++6.0
0
 
LVL 5

Accepted Solution

by:
millsoft earned 2000 total points
ID: 11787839
Hi mcCainz,

I can guarantee it's possible, since I do exactly that in my code, but my implementation uses a lot of code (including an XML generator for the SOAP request.)

However, basically, all you have to do is send XML via HTTP (or HTTPS), and retrieve the response XML and parse it.

For that, you can see the VC sample HEREX.EXE: http://download.microsoft.com/download/ie4095/hsrex/1/win98/en-us/Hsrex.exe  (C++ program posted below).

To apply this sample to your soap problem, create a file with the full XML of the SOAP request you want to send, and then modify the UseHTTPSendReqExec function to read your file and send it as the data.

Brad

#include <Windows.h>
#include <WinINet.h>
#include <stdio.h>

BOOL UseHttpSendReqEx(HINTERNET hRequest, DWORD dwPostSize);
#define BUFFSIZE 500

void main( int argc, char **argv )
{
    DWORD dwPostSize;

    if (argc < 4)
    {
        printf("Usage: Bigpost <Size> <Server> <Path>\n");
        printf("<Size> is the number of KB to POST\n");
        printf("<Server> is the server to POST to\n");
        printf("<Path> is the virtual path to POST to\n");
        exit(0);
    }

    if ( ((dwPostSize = strtoul(argv[1],NULL,10)) == 0) || (dwPostSize >= 2047999) )
    {
        printf("%s is invalid size.  Valid sizes are from 1 to 2047999\n", argv[1]);
        exit(0);
    }

    printf( "Test of POSTing %luKB with WinInet\n", dwPostSize);

    dwPostSize *= 1024;  // Convert KB to bytes

    HINTERNET hSession = InternetOpen( "HttpSendRequestEx", INTERNET_OPEN_TYPE_PRECONFIG,
        NULL, NULL, 0);
    if(!hSession)
    {
        printf("Failed to open session\n");
        exit(0);
    }


    HINTERNET hConnect = InternetConnect(hSession, argv[2], INTERNET_DEFAULT_HTTP_PORT,
        NULL, NULL, INTERNET_SERVICE_HTTP,NULL, NULL);
    if (!hConnect)
        printf( "Failed to connect\n" );
    else
    {
        HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", argv[3],
            NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
        if (!hRequest)
            printf( "Failed to open request handle\n" );
        else
        {
            if(UseHttpSendReqEx(hRequest, dwPostSize))
            {    
                char pcBuffer[BUFFSIZE];
                DWORD dwBytesRead;

                printf("\nThe following was returned by the server:\n");
                do
                {    dwBytesRead=0;
                    if(InternetReadFile(hRequest, pcBuffer, BUFFSIZE-1, &dwBytesRead))
                    {
                        pcBuffer[dwBytesRead]=0x00; // Null-terminate buffer
                        printf("%s", pcBuffer);
                    }
                    else
                        printf("\nInternetReadFile failed");
                }while(dwBytesRead>0);
                printf("\n");
            }
            if (!InternetCloseHandle(hRequest))
                printf( "Failed to close Request handle\n" );
        }
        if(!InternetCloseHandle(hConnect))
            printf("Failed to close Connect handle\n");
    }
    if( InternetCloseHandle( hSession ) == FALSE )
        printf( "Failed to close Session handle\n" );

    printf( "\nFinished.\n" );
}



BOOL UseHttpSendReqEx(HINTERNET hRequest, DWORD dwPostSize)
{
    INTERNET_BUFFERS BufferIn;
    DWORD dwBytesWritten;
    int n;
    BYTE pBuffer[1024];
    BOOL bRet;

    BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS ); // Must be set or error will occur
    BufferIn.Next = NULL;
    BufferIn.lpcszHeader = NULL;
    BufferIn.dwHeadersLength = 0;
    BufferIn.dwHeadersTotal = 0;
    BufferIn.lpvBuffer = NULL;                
    BufferIn.dwBufferLength = 0;
    BufferIn.dwBufferTotal = dwPostSize; // This is the only member used other than dwStructSize
    BufferIn.dwOffsetLow = 0;
    BufferIn.dwOffsetHigh = 0;

    if(!HttpSendRequestEx( hRequest, &BufferIn, NULL, 0, 0))
    {
        printf( "Error on HttpSendRequestEx %d\n",GetLastError() );
        return FALSE;
    }

    FillMemory(pBuffer, 1024, 'D'); // Fill buffer with data

    bRet=TRUE;
    for(n=1; n<=(int)dwPostSize/1024 && bRet; n++)
    {
        if(bRet=InternetWriteFile( hRequest, pBuffer, 1024, &dwBytesWritten))
            printf( "\r%d bytes sent.", n*1024);
    }
       
    if(!bRet)
    {
        printf( "\nError on InternetWriteFile %lu\n",GetLastError() );
        return FALSE;
    }

    if(!HttpEndRequest(hRequest, NULL, 0, 0))
    {
        printf( "Error on HttpEndRequest %lu \n", GetLastError());
        return FALSE;
    }

    return TRUE;
}

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question