Hi, I am trying to write data into SQL server using WCF service in Silverlight, but when i tried to do it, i get this exception:
System.ServiceModel.CommunicationException was unhandled by user code
Message=The remote server returned an error: NotFound.
StackTrace:
at System.ServiceModel.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.ServiceChannel.EndCall(String action, Object[] outs, IAsyncResult result)
at System.ServiceModel.ClientBase`1.ChannelBase`1.EndInvoke(String methodName, Object[] args, IAsyncResult result)
at SL_PilgrimManagement.DBSourceService.DBDataServiceClient.DBDataServiceClientChannel.EndAddNewPilgrim(IAsyncResult result)
at SL_PilgrimManagement.DBSourceService.DBDataServiceClient.SL_PilgrimManagement.DBSourceService.DBDataService.EndAddNewPilgrim(IAsyncResult result)
at SL_PilgrimManagement.DBSourceService.DBDataServiceClient.OnEndAddNewPilgrim(IAsyncResult result)
at System.ServiceModel.ClientBase`1.OnAsyncCallCompleted(IAsyncResult result)
InnerException: System.Net.WebException
Message=The remote server returned an error: NotFound.
StackTrace:
at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelAsyncRequest.CompleteGetResponse(IAsyncResult result)
InnerException: System.Net.WebException
Message=The remote server returned an error: NotFound.
StackTrace:
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClass5.<endgetresponse>b__4(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<beginonui>b__1(Object sendState)
InnerException:
</beginonui></endgetresponse>
one of the field is a
varbinary(MAX)
type, which i use to store images, and i did this in this way:
Stream photosream = browse.File.OpenRead();
BitmapImage bm = new BitmapImage();
photobytes = (new BinaryReader(photosream)).ReadBytes((int)browse.File.Length);
bm.SetSource(photosream);
image1.Source = bm;
here
photobytes
is a class attribute of
byte[]
type, and one thing that makes me even more confused is, there was a time where i forgot initialize the photobytes, and it didnt throw the exception. but of course the photo field at the SQL db is empty, but the others field are filled correctly...
where did i do wrong?
edit: im not getting any answer, maybe im not clear enough, let me add some points,
as i said before, there was a case where i forgot to initialiaze the
photobytes
, by that i mean at the method,
i mistakenly declared a new variable, something like this:
Stream photosream = browse.File.OpenRead();
BitmapImage bm = new BitmapImage();
byte[] photobytes = (new BinaryReader(photosream)).ReadBytes((int)browse.File.Length);
bm.SetSource(photosream);
image1.Source = bm;
and the service call run correctly, and the data is added to the database, although the image field is left null..
and i dont think this is a connection problem, as the service call to get the content of the table work correctly without any problem... what could cause this?
edit 2: i browsed around, and i think what caused the error was because i tried to pass array of bytes to the WCF Service call.. my service call is something like this:
DataServiceClient svc = new DataServiceClient();
svc.AddNewRecordAsyncCompleted += *Event Handling Here*
svc.AddNewRecordAsync(PKField, *Other Fields here*, photobytes);
while at the OperationContract definition itself, it would be something like this:
DBSourceDataContext db = new DBSourceDataContext();
Table<dbtable> tbl = db.GetTable<dbtable>();
dbtable tblRecord = new dbtable();
tblRecord.ID = PKField;
tblRecord.photo = new Binary(Photo);
tbl.InsertOnSubmit(tblRecord);
tbl.Context.SubmitChanges();</dbtable></dbtable>
I googled on how am i supposed to pass the data to the service, and it seems like im supposed to pass a stream object to the service call, but it would only allow me to pass that stream as the argument, and i would have no way to associate the image uploaded with the record that is being inserted.. how should i do this?