|
Hi all, I am attempting to save images from the desktop in a folder on the server using the following web service code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.Services;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
namespace MultipleImageUploadDemo
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class SaveImageService : System.Web.Services.WebService
{
public SaveImageService()
{
}
[WebMethod]
public void ProcessRequest(HttpContext context)
{
if (context.Request.Files.Count > 0)
{
HttpFileCollection files = context.Request.Files;
foreach (string key in files)
{
HttpPostedFile file = files[key];
string fileName = file.FileName;
fileName = context.Server.MapPath("~/Upload/" + fileName);
file.SaveAs(fileName);
}
}
context.Response.ContentType = "image/JPEG";
context.Response.Write("File(s) uploaded successfully!");
}
}
}
I got the following error when I try to run the web service:
System.Web.HttpContext cannot be serialized because it does not have a parameterless constructor.
I looked up the error message online and many posts I came across suggest that I create a parameterless constructor in my web service class which is responsible for deserializing the binary data. I tried that as you can see in my code, but I still get the same error message. If you think there is something else I should try please help. Thanks in advance for your help.
|
|
|
|
|
WebMethod attributes creates a method public and visible outside of your class. To enable to any client call that method the framework/compiler will create a proxy for the method (after all not every client what HttpContext is!). As part of that proxy the call and return parameters are serialized into XML or JSON...That's the part where you run into problem. Your input parameter is of type HttpContext, and that type can not be serialized...
It means that you can not create a method that will receive such a parameter!
In anyway it is sound extremely strange to me! Why should you get HttpContext as call parameter?
As it seams you try to upload files via web service call, you should do some search for samples...
One I found is here: http://blogs.msdn.com/b/codefx/archive/2012/02/23/more-about-rest-file-upload-download-service-with-asp-net-web-api-and-windows-phone-background-file-transfer.aspx[^]
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
תפסיק לספר לה' כמה הצרות שלך גדולות, תספר לצרות שלך כמה ה' גדול!
|
|
|
|
|
My requirements are simple. I need something with the following:
* queue like behavior (FIFO)
* thread-safe
* blocking behavior for get item method
* blocking get item method should be cancellable (cancellationtoken, bool, etc)
* blocking behavior should be 0% CPU / non spinning (no sleeps)
* high performance
So, naturally, I went with BlockingCollectionT. This works fine, and meets all my requirements, however, when you use the cancellable Take(CancellationToken) and cancel the operation, you get 3 exceptions:
A first chance exception of type 'System.OperationCanceledException' occurred in mscorlib.dll
A first chance exception of type 'System.OperationCanceledException' occurred in mscorlib.dll
A first chance exception of type 'System.OperationCanceledException' occurred in System.dll
The first 2 are caught inside of the framework and the 3rd I catch in my code. This causes people to complain I tried explaining this is "expected behavior", but you know people...
I looked at BlockingCollectionT in ILSpy and it doesn't seem like its going to be possible to bypass the exception throwing. GOD, I hate APIs that throw exceptions for "normal" behavior.
Seems like everything that uses the cancellationtoken throws exceptions on cancellation?
Any other options that don't throw exceptions on a cancellation?
|
|
|
|
|
"Blocking" and "High performance" are not very compatible.
SledgeHammer01 wrote: Any other options that don't throw exceptions on a cancellation? Catching exceptions is not that expensive. It is with the debugger attached, but you can throw and handle quite a lot of exceptions in a single second if there's no debugger attached.
SledgeHammer01 wrote: Seems like everything that uses the cancellationtoken throws exceptions on
cancellation? Implement your own, disallow cancelling; problem solved.
It would be a cool subject for a CodeProject-contest; writing a fast, multithreaded queue.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
SledgeHammer01 wrote: * blocking get item method should be cancellable (cancellationtoken, bool, etc)
Never understood that need. That can only apply if getting the item requires acquiring other resources and in that case, especially given 5, then either make the caller responsible for that or wrap it is a proxy and that does it.
SledgeHammer01 wrote: I hate APIs that throw exceptions for "normal" behavior.
Its a generic class/API which means if there is a failure mode then it must throw exceptions. If that isn't desirable then write your own. Not that hard and I suspect there are a vast number of examples on the internet.
|
|
|
|
|
jschell wrote: Never understood that need. That can only apply if getting the item requires
acquiring other resources and in that case, especially given 5, then either make
the caller responsible for that or wrap it is a proxy and that does it.
I have a worker thread that monitors the queue. There is not always something in the queue. In fact, most of the time, it will be empty or close to it. Clearly, I should not spin the CPU when the queue is empty.
As for being able to cancel the blocking operation, well... if you wait on a syncronization object indefinitely (the blocking part), it keeps the thread alive (which will keep the process alive) [EDIT: unless the thread is a background thread]. Not a desirable behavior when you, say, want to be able to shut down your app .
Using a timeout is also not a solution, as if you set your timeout too low, you'll spin the CPU, and if you set it too high, you'll have that annoying behavior of your app taking a long time to shut down.
jschell wrote: Its a generic class/API which means if there is a failure mode then it must
throw exceptions.
I wouldn't consider cancelling a blocking operation to be a failure if the cancellation was intended. But some would...
jschell wrote: Not that hard
and I suspect there are a vast number of examples on the internet.
You'd be surprised .
|
|
|
|
|
How to calculate matrix determinant? n*n
|
|
|
|
|
Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...
A very quick search using your subject as the search term gave 71 million hits: Google: "How to calculate matrix determinant? n*n"[^]
In future, please try to do at least basic research yourself, and not waste your time or ours.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Where are you stuck?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I have a DVR and configured my router for NAT Forwarding to my web (9000) and media (9100) port. Using a browser and in different network, I cannot access my DVR's web port and see real-time using IE.
I would like to ask where to begin in programming using C# to develop and application for Windows Phone 8.x or Android for my DVR's media port.
Thanks!
|
|
|
|
|
Strange port numbers are often blocked by the ISP. Try another port.
Benjie Fallar III wrote: real-time using IE. You mean "live". Windows isn't a realtime OS.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: Windows isn't a realtime OS.
The deuce you say.
|
|
|
|
|
I have NO problem accessing the media port via LAN/WLAN.
My question is how or where can I start developing a C# programming that capture the live streaming of my DVR cameras from a network.
For example, my DVR media port is 9100 and the IP is 192.168.1.3, thus how can I read the live stream from 192.168.1.3:9100 using C#.
|
|
|
|
|
I have NO problem accessing the media port via LAN/WLAN.
My question is how or where can I start developing a C# programming that capture the live streaming of my DVR cameras from a network.
For example, my DVR media port is 9100 and the IP is 192.168.1.3, thus how can I read the live stream from 192.168.1.3:9100 using C#.
|
|
|
|
|
Benjie Fallar III wrote: I have NO problem accessing the media port via LAN/WLAN.
I cannot access my DVR's web port and see real-time using IE.
Benjie Fallar III wrote: where can I start developing a C# programming that capture the live streaming of
my DVR cameras Do you know the format of the stream? Any other application that accepts the address/port and can display the stream?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
the streaming format is H.264
is there any online documentation or reference on how to start programming live streaming from DVR using C#.NET?
In some Adroid app, like ViewCam, they can connect to remote DVR. I wanted to develop the same application for Windows Phone. So I'm looking for some references to starts with
|
|
|
|
|
Benjie Fallar III wrote: is there any online documentation or reference on how to start programming live
streaming from DVR using C#.NET? You'd need some library to decode the stream and a control to display it. Decoding is usually not done in C#, but using an external library. VLC should be able to do it.
http://libvlcnet.codeplex.com/[^]
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I would like to make an application to register queries in SQL files or XML file .
Is what you have ideas?
Thank you
|
|
|
|
|
Ibrahim.elh wrote: I would like to make an application to register queries in SQL files or XML file . Do you want to detect "SQL code" in those files, or do you want to log stuff that is executed?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I try to make an application that recovers the script of the table and put them in a database
|
|
|
|
|
You'll have to explain more; what script do you want to recover?
You can generate a SQL Script to (re)create the table.
What does putting a script in a database mean here? Executing the script on a database, or actually saving it as data?
I suppose you stopped trying virtualizing the gridview?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
yes I stop trying viruel mode I found another solution , I wish to make an application that connects to a database on a server and saves in csv or sql script to either import it on a mysql database
|
|
|
|
|
Ibrahim.elh wrote: wish to make an application that connects to a database on a server and saves in
csv or sql script to either import it on a mysql database Most databases can export to CSV, and shouldn't be too hard since Informix allows access over ODBC.
That would only export the data, not the structure, the relations or any server-side logic.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
i have a informix database
|
|
|
|