Reputation: 7690
I'm using an external web service method from my website on my silverlight app. which is supposed to return details of my videos in database as a jagged array. There should be no problem as i know of.
But every other method in the same service is firing completed events instead of this one, i also looked at its return value and its working as i want to. What am i doing wrong here?
Here is my wcf webservice hosted on my website;
[OperationContract]
public Object[][] compilationRequestsDetails(string ownerId, string senderId)
{
SqlConnection objConnection = new SqlConnection();
objConnection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnStr"].ToString();
objConnection.Open();
SqlDataAdapter adapter = new SqlDataAdapter();
SqlCommand objCommand = new SqlCommand("SELECT video.id ,name, vidLength, lowPath, instruments.logo, mp3Path FROM video LEFT JOIN instruments ON video.instrumentId = instruments.id LEFT JOIN compilations ON video.compilationId = compilations.id \n"
+"WHERE video.id='"+ownerId+"' OR video.id='"+senderId+"' OR compilationId ='" +ownerId+"'");
adapter.SelectCommand = objCommand;
adapter.SelectCommand.Connection = objConnection;
SqlDataReader reader = adapter.SelectCommand.ExecuteReader();
List<Object[]> videos = new List<Object[]>();
while (reader.Read())
{
Object[] values = new Object[reader.FieldCount];
reader.GetValues(values);
videos.Add(values);
}
Object[][] result = videos.ToArray();
reader.Close();
objConnection.Close();
return result;
}
it returns as its expected;
Edit: Thanks to carlosfigueira i've updated my service call as following, and found out that i'm getting no data in silverlight app.
myServiceRef.compilationRequestsDetailsCompleted +=new EventHandler<myService.compilationRequestsDetailsCompletedEventArgs>(myServiceRef_compilationRequestsDetailsCompleted);
}
void myServiceRef_compilationRequestsDetailsCompleted(object sender, myService.compilationRequestsDetailsCompletedEventArgs e)
{
if (e.Error == null)
{
MessageBox.Show("fetch ended result count:" + e.Result.Length);
}
else
{
MessageBox.Show("Error: " + e.Error);
}
and the error that it gives me is this;
my reference configuration is for System.Array and it should be enough for return type Object[][]
.
I'd appreciate if you can tell me why i am getting no data.
Problem must be in the initialization of the jagged array because if i write a dummy array like this and initialize as following, i can get the data from the silverlight like this in the same method;
objConnection.Close();
Object[][] j2 = new Object[][]
{
new Object[] {0,2,4,6},
new Object[] {11,22}
};
return j2;
but still couldn't found a way to correctly pass my result array to the application.
I've solved it in a way that i didn't really like but gee its done! I've downloaded fiddler, and the client side had a problem with the type. it was a problem with systemknowntype as carlosfigueira said, so i needed to cast the values to string before sending to the app.
Thanks for the help!
Upvotes: 1
Views: 1178
Reputation: 87228
The event is likely firing, but if you have an error you cannot access e.Result
, since it will throw an exception. Replace the event handler code with
void myServiceRef_compilationRequestsDetailsCompleted(
object sender, myService.compilationRequestsDetailsCompletedEventArgs e)
{
if (e.Error == null)
{
MessageBox.Show("fetch ended result count:" + e.Result.Length);
}
else
{
MessageBox.Show("Error: " + e.Error);
}
}
Now, if you really have an error, you'll need to find out why you have it. Without looking at the code, one thing that pops out is that your operation is declared to return object[][], and with WCF you usually need to declare all the types which will be used with ServiceKnownType
. But the best way to find out the actual error is to enable tracing at the server side, the traces should contain information about the error itself.
Upvotes: 2