c# - WCF service - Return int from "Method = 'DELETE'" -


i'm trying sort of exception control in service (returning simple integers , handling these in gui), i've stumbled upon difficulty.

in of post, , put return either 1 or -1 (depending on exception receive), can't seem return integer delete method.

this approach:

iservice.cs

[operationcontract] [webinvoke(method = "delete", uritemplate = "/logins/delete/{stringid}")] int deletelogin(string stringid); 

service.cs

/// <summary> /// deletes login given stringid /// </summary> /// <param name="stringid"></param> public int deletelogin(string stringid) {     try     {         var id = int32.parse(stringid);         var dblogin = dao.hourreginstance.login.singleordefault(x => x.id == id);         dao.hourreginstance.login.remove(dblogin);         dao.hourreginstance.savechanges();         return 1;     } catch(exception e){         return -1;     } } 

don't waste time explaining me catch specific exceptions. test environment

ajax call

 function deleteuser() {     $.ajax({         type: "delete",         url: baseaddress + "logins/delete/" + user.id,     }).done(function (code) {         if (code === 1) {             devexpress.ui.notify('your account has been deleted!', 'success', 3000);             hourregistrationapplication.app.navigate({                 view: "login"             })         } else if (code === -1) {             devexpress.ui.notify('something went wrong, please try again.', 'error', 3000);             hourregistrationapplication.app.navigate({                 view: "loginprofile"             })         }     }).error(function (err) {         console.log(err);          devexpress.ui.notify('something went wrong, please try again.', 'error', 3000);         hourregistrationapplication.app.navigate({             view: "loginprofile"         })     }) } 

this returned:

enter image description here

is there way me return integer delete method? or not possible?

i managed solve problem on own.

in data annotation, replaced this:

[webinvoke(method = "delete", uritemplate = "/logins/delete/{stringid}")] 

with this:

[webinvoke(method = "delete", responseformat = webmessageformat.json, uritemplate = "/logins/delete/{stringid}")] 

basically added responseformat = webmessageformat.json


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -