views:

590

answers:

2

Hi,

I have a problem that googling couldn't solve it.

I have a REST WCF service that will be called from a form like this and upload a very small plain text file:

<form action="http://www.server.com/myService.svc/Upload"  encType="multipart/form-data" method="POST">
   SERIALID <input type="text" size="20" name="SERIALID" value=""><br>
   PASSWORD <input type="text" size="20" name="PASSWORD" value=""><br>
   LOGFILE <input type="file" size="20" name="LOGFILE" id="LOGFILE"> (select a log file here)<br>
   <br>
   <input type="submit" name="submitbutton" value="Submit"></p>
</form>

I copied the code from http://stackoverflow.com/questions/1354749/wcf-service-to-accept-a-post-encoded-multipart-form-data.

I used only the Stream parameter because if you have a Stream parameter you can't have any other parameters. I tried adding all the form variables as parameters but didn't let me.

[ServiceContract]
public interface IUploadWebService
{
    [OperationContract]
    [WebInvoke(
        Method = "POST",
        BodyStyle = WebMessageBodyStyle.Bare,
        UriTemplate = "/Upload")]
    void UploadFile(Stream LOGFILE);

}

This is part of the web.config:

<system.serviceModel>
  <bindings>
    <webHttpBinding>
      <binding name="WebConfiguration"
             maxBufferSize="65536"
             maxReceivedMessageSize="2000000000"
             transferMode="Streamed">
    </binding>
  </webHttpBinding>
</bindings>

<endpoint address="" binding="webHttpBinding" behaviorConfiguration="WebBehavior"    bindingConfiguration="WebConfiguration"
        contract="WebServices.IUploadWebService" />

When the service is called the client gets a HTTP/1.1 400 Bad Request error.

Any help will be appreciated.

Thanks.

A: 

Did you set Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory" in your .svc file?

Darin Dimitrov
I just did, but didn't help it, thanks.
anon2009
+1  A: 

Problem solved.

I used some real tracing and I found the exception.

Thank you all for your help.

anon2009