asp.net - Returning an output value via C# WCF service -
i'm looking return string value client via http post service on wcf.
i can return status code okay via following:
weboperationcontext.current.outgoingresponse.statuscode = httpstatuscode.ok;
... i'm not entirely sure how return string value client.
any pointers appreciated.
thanks
nick
namespace textwcf { [servicecontract] public interface ishortmessageservice { [webinvoke(uritemplate = "invoke", method = "post", bodystyle = webmessagebodystyle.wrappedrequest)] [operationcontract] void postsms(stream input); } } [operationbehavior] public void postsms(stream input) { streamreader sr = new streamreader(input); string s = sr.readtoend(); sr.dispose(); namevaluecollection qs = httputility.parsequerystring(s); string user = convert.tostring(qs["user"]); string password = qs["password"]; string api_id = qs["api_id"]; string = qs["to"]; string text = qs["text"]; string = qs["from"]; weboperationcontext.current.outgoingresponse.statuscode = httpstatuscode.ok; weboperationcontext.current.outgoingresponse. = httpstatuscode.ok; }
you need have method return neil pointed out.
so change method signature like
namespace textwcf { [servicecontract] public interface ishortmessageservice { [webinvoke(uritemplate = "invoke", method = "post", bodystyle = webmessagebodystyle.wrappedrequest)] [operationcontract] string postsms(stream input); } } [operationbehavior] public string postsms(stream input) { streamreader sr = new streamreader(input); string s = sr.readtoend(); sr.dispose(); namevaluecollection qs = httputility.parsequerystring(s); string user = convert.tostring(qs["user"]); string password = qs["password"]; string api_id = qs["api_id"]; string = qs["to"]; string text = qs["text"]; string = qs["from"]; weboperationcontext.current.outgoingresponse.statuscode = httpstatuscode.ok; weboperationcontext.current.outgoingresponse. = httpstatuscode.ok; return "some string"; }
Comments
Post a Comment