views:

154

answers:

2

I have a Web Service method developed using .NET 3.5 (VS2008) which expects a few strings (username, password, subject, file type) and a binary document coded in Base64.

I enabled both SOAP and HTTP POST. While SOAP works perfectly, it is not possible to send HTTP POST requests. The server responses with "Server was unable to process request. ---> Data at the root level is invalid. Line 1, position 1".

Customers are using this method to upload their documents from their applications.

I was told that .NET does not support complex structures using HTTP POST. Any way to support this?

A: 

It sounds like you want to shift from a desktop app to an asp web based application.

While that is usually a great idea I think you will be fighting an uphill battle in trying to post files via http/form to your web service. While technically it is possible I am having a hard time thinking of an implementation.

You might have better luck using a form as a proxy with your input variables and a file input to submit to a form, e.g. a webform, and use the codebehind on the webform to spin up an instance of your webservice class (no need to use a proxy, you are already on your side of the wire).

If this does not make sense let me know and if it cannot be made to fit your scenario please update your question to more clearly state your desired outcome.

If you are doing this via Ajax decorate your service class with [ScriptService] attribute and post JSON via xmlhttp. You can easily send complex arguments.

see http://www.codeproject.com/Articles/38999/Consuming-ASP-net-WebServices-WCF-Services-and-sta.aspx for instructions.

If you are not, please elaborate on what is doing the posting and how you are packing the data.

Sky Sanders
I've updated my question: customers are accessing this method to upload their documents to my service.
@user240113, i have updated my answer. I think you need to rethink your planned approach and am willing to help. elaborate on your desired outcome.
Sky Sanders
+1  A: 

.NET does support complex structures using POX (plain old xml) with the httpBinding. Here is an article that explains how to set it up: http://fluxcapacity.net/2007/11/06/how-to-create-restpox-web-services-with-wcf/

Note: All SOAP, XML and JSON dto updates still work over HTTP POST - SOAP just wraps your payload with additional markup, which effectively just adds additional overhead and complexity for website (i.e. Ajax) clients.

If you want your same webservice to work over SOAP as well as other endpoints e.g. XML or JSON you may be interested in this opensource webservices framework which enables all these endpoints without any additional configuration.

mythz