views:

2774

answers:

2

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?

+4  A: 

Hey Brian,

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.

James Bender
James - thanks for the info! Off to research wcf channels...
BryanB
A: 

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.

Eric Lynch