Transactional webservice

  • Thread starter Thread starter David
  • Start date Start date
D

David

Hi all,

I have written a webservice, and certain things need to happen in a certain
order and with a transactional nature. Ignore DB transactions at this
point...


For example...

Coming into the webservice will be an ApplicationName. Also coming in will
be some files. It can be one, it can be many. No files can be handled until
the application name has been set, (for this, I have a property, the file
handler will check this property before handling files).

Once the files have been handled, I then need to process them.


The current steps in my calling app are:

ph.ApplicationName(appname);
ph.FileCount(fileCount);
foreach (file in fileList)
{
// Ignore syntax...
ph.PutFile(bytebuffer, filename);
}
ph.ProcessFiles();


So, what is happening at the webservice itself is that it appears that
applicationname (which is populating a private property called appname) is
not set properly. It gets set, but when I come to PutFile, I check if the
appname (and filecount) have been set and if so, then PUT the files.

Am I missing something? I need to have all the values set. Especially when
it comes to handling the files, I need for a file list on the webservice,
but if it is not remembering, then I am not sure I can do it that way.

Any ideas would be appreciated.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
Hi Patrice,

ph is basically a connection to my webservice.

I could do it as an atomic transaction, but I am not sure how to transmit
multiple files in one hit. (At the point of uploading, I know how many
files, but the amount can be variable, for example, it won't always be two
files.).

If I was to use session state, how would I do that? At the webservice end or
the windows service end? I am guessing the webservice end.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
Hi,

I will look at storing the files in an array (or arraylist, or even a
List<>). I wasn't sure how I could do that, but will investigate further.

The files (probably up to about 6 files) will be fairly small. It will be an
XML file of a few k, a PDF, prob up to 200K and maybe up to 4 mobile phone
photos (the phone users will be told that they have to use lower resolution
in order to save mobile message bandwidth... I might even do some other
local resizing to reduce file size...)

So, not in hundreds of MB, just a few hundred KB (all being well).
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
Hi Patrice,

I have changed my code to attempt to do an atomic upload, upload everything
in one hit.

However, I am having problems you might be able to help me with.

I was trying to use List<string> to contain all my filenames and
List<byte[]> to contain the actual files. However, List<> is not supported
by webservices. :-(

So, eventually, I have gone to an ArrayList to contain my filenames (as
string) and another ArrayList to contain my files (as byte[]). However, the
webservice moaned about trying to convert ArrayList to Object. So, I cast my
arraylists as objects on the calling side, and changed my parameters in the
webservice to object, then inside the web service function, I am casting
back the objects to arraylist.

This built, but doesn't work. Apparently, my calling function cannot
generate the xml. (Here is the error)

An unhandled exception of type 'System.InvalidOperationException' occurred
in System.Xml.dll

Additional information: There was an error generating the XML document.

(I will try an array, but if you have any other useful info, it would be
appreciated.)


Here is the relevant code that I am trying...


// THIS IS IN MY LOCAL WINDOWS SERVICE

ArrayList FilesList = new ArrayList();

foreach (string file in FileNames)
{

System.IO.BinaryReader br = new
System.IO.BinaryReader(System.IO.File.Open(currentDirectory + "\\" + file,
System.IO.FileMode.Open, System.IO.FileAccess.Read));
br.BaseStream.Position = 0;
byte[] buffer =
br.ReadBytes(Convert.ToInt32(br.BaseStream.Length));

FilesList.Add(buffer);

br.Close();

}

ph.UploadData(SubjectParts[1].Trim(), FileCount,
(object)FileNames, (object)FilesList);

// FileNames is being fed in as a param to this function, but it is an
arraylist.



// THIS IS MY WEBSERVICE

[WebMethod]
public bool UploadData(string ApplicationName, int FileCount, object
FileNames, object FilesList)
{
AppName = ApplicationName; // AppName is a property
RemoteFileCount = FileCount; // RemoteFileCount is a property

ArrayList fileNames = (ArrayList)FileNames;
ArrayList filesList = (ArrayList)FilesList;

}


--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
Could do zip, but added complexity, got to zip it at one end then unzip at
other, plus the idea of the webservice is that we will use it direct without
the intermediate that I have written. The other sender might not be able to
zip.

I have it working now...

byte[] FilesList = new byte[filecount][];

then add my files (converted to bytes) within a loop...

FilesList = ByteVersionOfFile;

This will now work to the webservice. The webservice being...

uploadFiles(byte[][] FilesList)


Gutted that List<byte[]> doesn't work though. I was just starting to get
into generics.

--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
Back
Top