sending post data to WCF in Titanium -
below code titanium:
var request = titanium.network.createhttpclient(); request.open("post", bh.serveraddress + "mycareer.svc/postmessage/"+ bh.userid + "/" + bh.logic.profile.userid); request.setrequestheader("enctype", "multipart/form-data"); request.setrequestheader("content-type", "text/json"); request.send(data_to_send); request.onload = function() { ti.api.info(this.responsetext); bh.ui.profile.createwindow(); }; request.onerror = function(){ alert('error while posting message'); }; below code wcf:
interface:
[operationcontract] [webinvoke(method = "post", uritemplate = "/postmessage/{userid}/{touserid}", bodystyle = webmessagebodystyle.wrappedrequest, responseformat = webmessageformat.json, requestformat = webmessageformat.json)] int postmessage(string userid, string touserid, string message); class:
public int postmessage(string userid, string touserid, string message) { mdbdatacontext omdb = new mdbdatacontext(); int returnvalue = omdb.postmessage(convert.toint32(userid), message, convert.toint32(touserid)); omdb.dispose(); return returnvalue; } query: if convert functionality "get" works fine. but, "post" error , unable figure out error. have enable tracelistener wcf, no error there.
please help. stuck @ point. trying iphone simulator.
finally, found problem in code. , solution apply every client side technology.
let's see working code first:
var data_to_send = '{"userid": "' + bh.userid + '", "touserid": "' + bh.logic.profile.userid + '","message": "' + bh.ui.postmessage.txtpost.value + '"}'; var request = titanium.network.createhttpclient(); request.onload = function() { //some code here }; request.onerror = function(){ //some code here }; request.open("post", bh.serveraddress + "mycareer.svc/postmessage"); request.setrequestheader("enctype", "multipart/form-data"); request.setrequestheader("content-type", "application/json; charset=utf-8"); request.send(data_to_send); fixes:
- the json data sending not in correct format. created json string should had been consumed in local javascript. but, json had consumed wcf. so, should remain json time reaches there. notice use of single , double quotes. should are. think interchanging them should not work because single quotes in asp.net means character , not string.
- notice use of header information sending. think variation in shall work, atleast application/json thing required.
hope helps. whole point deem correct javascript not correct json.
Comments
Post a Comment