c# - Value does not fall within the expected range when calling REST web service in windows phone 8 app -
i've been struggling hours on one. keep getting "value not fall within expected range" when call 1 of web service functions. i'm using post method i'm passing json object , expecting json data returned.
it doesn't make sense i've got other web service functions working , annoyingly, works when called fiddler 2.
i'm calling following code in try/catch
string jsonresponse = await wc.uploadstringtaskasync(new uri(app.webserviceuri + "/json/getdocumentbydocid"), jsonrequest); i've put break points in code , when called fiddler, goes specific function when called through code, generates exception "value not fall within expected range" isn't caught in try/catch
it bombs out straight
private void application_unhandledexception(object sender, applicationunhandledexceptioneventargs e)
maybe it's not being caught try/catch because i'm calling async function:
public static task<string> uploadstringtaskasync(this webclient wc, uri url, string data) { var tcs = new taskcompletionsource<string>(); wc.uploadstringcompleted += (s, e) => { if (e.error != null) tcs.trysetexception(e.error); else if (e.cancelled) tcs.trysetcanceled(); else tcs.trysetresult(e.result); }; wc.uploadstringasync(url, "post", data); return tcs.task; } but still doesn't explain error. i'm not dealing list or similar, again have assume it's related uri, that's not either!
after error caught in application_unhandledexception, , continue running app, calls code , returns appropriate data app has bombed out.
it doesn't make sense! json object pass simple poco object contains string (table name), long (docid) , int (page no) , returns poco object, again none containing list or similar, don't understand error mean , why work every other functions defined in web service.
any ideas?
thanks.
update:
this second time i'm changing answer!! deleted original 1 , thought had fixed , provided details wasn't correct reason.
i'm fed getting wrong @ least i'm learning in process error still doesn't make sense, @ least not me!
i thought related dodgy xaml, or not having lazy load when calling async function constructor, that's not case.
while had dodgy code, i'm pretty sure i've cleared , set expected i'm still getting error.
i have third-party control needs on usercontrol. usercontrol has single property i.e. sourcefile of type string
public string sourcefile { { return _sourcefile; } set { _sourcefile = value; } } this property binded property viewmodel i.e. documenturi
public string documenturi { { return this._documenturi; } set { if (this._documenturi != value) { this.setproperty(ref this._documenturi, value); } } } the setproperty takes care of inotifypropertychanged , event handler being set.
now here xaml code:
<grid grid.row="1"> <stackpanel orientation="vertical"> <cc:viewer sourcefile="{binding documenturi}" /> </stackpanel> </grid> where cc:viewer usercontrol.
when set above, following error: "value not fall within expected range."
if remove sourcefile="{binding documenturi}", error disappears that's pointless need property display document when downloaded. confirms in fact linked property.
any ideas?
thanks.
thierry
i deleted original answer spotted causing problem , time i'm 100% sure of it.
while thought maybe related dodgy xaml, or not having lazy load when calling async function constructor, combination of things.
the error thrown totally misleading!! due combination of things:
- calling async constructor without using asynchronous initialization pattern.
- not checking if values blank in constructor , properties
- creating property in usercontrol wasn't binded. created regular property when should have in fact have created property using depencyproperty make bindable.
once of above correct, problem got sorted.
Comments
Post a Comment