Accepting form fields via HTTP Post in WCF
Asked Answered
K

2

7

I need to accept form data to a WCF-based service. Here's the interface:

[OperationContract]
[WebInvoke(UriTemplate = "lead/inff",
    BodyStyle = WebMessageBodyStyle.WrappedRequest)]
int Inff(Stream input); 

Here's the implementation (sample - no error handling and other safeguards):

public int Inff(Stream input)
{

    StreamReader sr = new StreamReader(input);
    string s = sr.ReadToEnd();
    sr.Dispose();

    NameValueCollection qs = HttpUtility.ParseQueryString(s);
    Debug.WriteLine(qs["field1"]);
    Debug.WriteLine(qs["field2"]);

    return 0;
}

Assuming WCF, is there a better way to accomplish this besides parsing the incoming stream?

Kenon answered 29/9, 2008 at 2:31 Comment(0)
A
5

I remember speaking to you about this at DevLink.

Since you have to support form fields the mechanics of getting those (what you are currently doing) don't change.

Something that might be helpful, especially if you want to reuse your service for new applications that don't require the form fields is to create a channel that deconstructs your stream and repackages it to XML/JSON/SOAP/Whatever and have your form clients communicate with the service through that while clients that don't use forms can use another channel stack. Just an idea...

Hope that helps. If you need help with the channel feel free to let me know.

Antilog answered 4/10, 2008 at 14:15 Comment(1)
James, I'm very interested in how you would implement this using WCF without form fields. Can you point me in a direction where I might get some more information on how to do this? Thanks in advance.Inkwell
B
0

You can serialize your form fields with jquery and package it as json request to wcf service.

Bedcover answered 3/4, 2012 at 16:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.