I'm cross posting, sorry, but this pertains to both sides..
I have a Web Services written in C# and a client written in VC6. I've
never uploaded files through web services so forgive my ignorance in this
matter, but I'm trying to understand how I can do this from the C++ client.
The C# code works for HTTP Form Posts, but not really what I'm looking for..
This should be for applications to upload files too.. The code is as
follows:
-----------------------------------------------------------------
[WebMethod]
public bool UploadFileColle ction()
{
try
{
//HTTP Context to get access to the submitted data
HttpContext postedContext = HttpContext.Cur rent;
//File Collection that was submitted with posted data
HttpFileCollect ion Files = postedContext.R equest.Files;
//Make sure a file was posted
//This works for HTTP Form Posts, need to understand how to make this
work for C++ posts
string fileName = (string)postedC ontext.Request. Form["fileName"];
if (Files.Count == 1 && Files[0].ContentLength 1 && fileName != null
&& fileName != "")
{
//The byte array we'll use to write the file with
byte[] binaryWriteArra y = new
byte[Files[0].InputStream.Le ngth];
//Read in the file from the InputStream
Files[0].InputStream.Re ad(binaryWriteA rray, 0,
(int)Files[0].InputStream.Le ngth);
//Open the file stream
FileStream objfilestream = new FileStream("c:\ \" + fileName,
FileMode.Create , FileAccess.Read Write);
//Write the file and close it
objfilestream.W rite(binaryWrit eArray, 0,
binaryWriteArra y.Length);
objfilestream.C lose();
return true;
}
else
{
return false;
}
}
catch (Exception ex1)
{
throw new Exception("Prob lem uploading file: " + ex1.Message);
}
}
-----------------------------------------------------------------
I have VC6 client that is to upload a file to the C# Web Services Interface
using WinHttp..
WinHttpOpen
WinHttpConnect
WinHttpOpenRequ est
WinHttpSetOptio n
WinHttpAddReque stHeaders
WinHttpWriteDat a //header
WinHttpWriteDat a //binary file in data chunks
WinHttpWriteDat a //footer
WinHttpReceiveR esponse
WinHttpQueryHea ders
WinHttpQueryDat aAvailable
WinHttpReadData
WinHttpCloseHan dle
I've never written anything in C++ to talk to Web Services before and I know
this code work for file uploads to IIS via ASPUpload object on the server.
I may be way off, but my searching is leading me no where.
I have a Web Services written in C# and a client written in VC6. I've
never uploaded files through web services so forgive my ignorance in this
matter, but I'm trying to understand how I can do this from the C++ client.
The C# code works for HTTP Form Posts, but not really what I'm looking for..
This should be for applications to upload files too.. The code is as
follows:
-----------------------------------------------------------------
[WebMethod]
public bool UploadFileColle ction()
{
try
{
//HTTP Context to get access to the submitted data
HttpContext postedContext = HttpContext.Cur rent;
//File Collection that was submitted with posted data
HttpFileCollect ion Files = postedContext.R equest.Files;
//Make sure a file was posted
//This works for HTTP Form Posts, need to understand how to make this
work for C++ posts
string fileName = (string)postedC ontext.Request. Form["fileName"];
if (Files.Count == 1 && Files[0].ContentLength 1 && fileName != null
&& fileName != "")
{
//The byte array we'll use to write the file with
byte[] binaryWriteArra y = new
byte[Files[0].InputStream.Le ngth];
//Read in the file from the InputStream
Files[0].InputStream.Re ad(binaryWriteA rray, 0,
(int)Files[0].InputStream.Le ngth);
//Open the file stream
FileStream objfilestream = new FileStream("c:\ \" + fileName,
FileMode.Create , FileAccess.Read Write);
//Write the file and close it
objfilestream.W rite(binaryWrit eArray, 0,
binaryWriteArra y.Length);
objfilestream.C lose();
return true;
}
else
{
return false;
}
}
catch (Exception ex1)
{
throw new Exception("Prob lem uploading file: " + ex1.Message);
}
}
-----------------------------------------------------------------
I have VC6 client that is to upload a file to the C# Web Services Interface
using WinHttp..
WinHttpOpen
WinHttpConnect
WinHttpOpenRequ est
WinHttpSetOptio n
WinHttpAddReque stHeaders
WinHttpWriteDat a //header
WinHttpWriteDat a //binary file in data chunks
WinHttpWriteDat a //footer
WinHttpReceiveR esponse
WinHttpQueryHea ders
WinHttpQueryDat aAvailable
WinHttpReadData
WinHttpCloseHan dle
I've never written anything in C++ to talk to Web Services before and I know
this code work for file uploads to IIS via ASPUpload object on the server.
I may be way off, but my searching is leading me no where.
Comment