views:

233

answers:

2

Hi guys I am calling a webmethod from C++. The [webmthod] is defined as follows

[WebMethod]
public string UploadFile(byte[] data)

Here is how I call it in C++

 static TCHAR hdrs[] = "Content-Type: application/x-www-form-urlencoded";
     static TCHAR frmdata[] = "data=temp.txt";
  HINTERNET hSession = InternetOpen("MyAgent",INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
  HINTERNET hConnect = InternetConnect(hSession, "localhost",
      INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
  HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", "my/WebService.asmx/UploadFile", NULL, NULL, 0, 0, 1);
  HttpSendRequest(hRequest, hdrs, strlen(hdrs), frmdata, strlen(frmdata));

With this; I receive the following error.

System.ArgumentException: Cannot convert temp.txt to System.Byte.

So how do I pass in the frmdata[] so that it can be converted to a System.byte on the webservice?

Thanks!

A: 

I ended up doing HTTP UPLOAD from C++..

shergill
+1  A: 

For future reference: consider using ATL Server. You can find latest bits and more information on www.codeplex.com/AtlServer (Microsoft pulled ATL Server out of latest ATL 9.0 SDK and moved it to codeplex), and MSDN: msdn.microsoft.com/en-us/library/exb5b09w(VS.80).aspx

For C++ you can generate a proxy header file that neatly wraps all you need to call the web method using ATL soap and whatever ATL Soap Client you wish (WinInet, WinHTTP, Soap Socket, etc) which handles all the network calls. To generate this file, you can use sproxy.exe tool. Then the web method call becomes a simple class method call.

Reference: msdn.microsoft.com/en-us/library/994721ak(VS.80).aspx Sproxy Tool: msdn.microsoft.com/en-us/library/ztta389h(VS.80).aspx Example WS call: msdn.microsoft.com/en-us/library/ftdya1d6(VS.80).aspx

Temich