views:

38

answers:

1

I am trying to have a HTML form post a file to a Asp .Net Web service method. Everything seems to work but there is no form or files on the request object in the web method. any ideas?

Html Form

<form id="formPost" action="service/Post" enctype="multipart/form-data" method="post">
    Post File <input id="uploadfile"    type=file />
    <input type=submit value="Post" />
</form>

Web service

[WebMethod]
    public void Post()
    {        
        // file collection of uploaded files in the http context
        HttpFileCollection Files = this.Context.Request.Files;

        // always 0 and no form either
        if (Files.Count > 0)
        {}
    }
A: 

You cannot post to a SOAP web service method using html form. When you submit the form data is encoded using multipart/form-data while a web service expects a SOAP envelope and text/xml content type. In order to invoke the web service you will need to generate a proxy class from the WSDL and use this proxy class to call the desired method.

Darin Dimitrov
Any chance of a link to some examples?
Kenoyer130
Darin Dimitrov
I ended up using a http handler as a better solution. Also, the file upload form element doesn't work without a name attribute. weird...
Kenoyer130