c# - How to handle URL-encoded POST request with self-hosted WCF? -


i have self-hosted wcf service. works charm, when input data format known, it's not case.

my service invoked html form posted it, don't know exact list of parameters sent.

external web service send http request content "a=foo&b=bar", yes, url-encoded. parameters in content may vary. count may vary. parameters may or may not present. i'm fine whole url-encoded string, i'll decode myself. have reply ascii string "ok".

how access "a=foo&b=bar" text request? can create own encoder? how it's done?

here's started with, contract:

[operationcontract] [webinvoke(method = "post", uritemplate = "test", bodystyle = webmessagebodystyle.bare)] stream testpostrequest(); 

and here's method:

public stream testpostrequest() {     var maxbytesize = 16384;     var messagestream = new memorystream(maxbytesize);     var messagebuffer = operationcontext.current.requestcontext.requestmessage.createbufferedcopy(maxbytesize);     messagebuffer.writemessage(messagestream);     var rawrequestdata = new byte[maxbytesize];     messagestream.read(rawrequestdata, 0, maxbytesize);     var requestdatastring = encoding.utf8.getstring(rawrequestdata);     console.writeline(requestdatastring);     var responsedata = new byte[2] { 79, 75 }; // ok     var responsestream = new memorystream(responsedata);     return responsestream; } 

obviously doesn't work, because createbufferedcopy method expects xml input data, gets url-encoded string. other methods found.

i'm not afraid of creating new class implementing iendpointbehavior or idispatchmessageinspector, don't see implement allowing me access request data raw, bytes, not xml.

maybe there point convert raw data xml?

edit:

my fault, there broken behavior in operation stack messed message content type badly. moral - test new features isolated, in clean test project. second moral wcf can ;) , third is: if there no xml in message internal data - broke ;)


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -