I have the following contract:
[OperationContract(Name = "Upload")]
[WebInvoke(Method = "POST", UriTemplate = "/Upload/{step}/{fileName}",
BodyStyle= WebMessageBodyStyle.WrappedRequest)]
Response FileUpload(string fileName, string step, Stream fileStream);
And the implementation:
public Response FileUpload(string fileName, string step, Stream fileStream)
{
FileStream fileToUpload = new FileStream("C:\\inetpub\\wwwroot\\Upload\\" + fileName, FileMode.Create);
byte[] bytearray = new byte[10000];
int bytesRead, totalBytesRead = 0;
do
{
bytesRead = fileStream.Read(bytearray, 0, bytearray.Length);
totalBytesRead += bytesRead;
} while (bytesRead > 0);
fileToUpload.Write(bytearray, 0, bytearray.Length);
fileToUpload.Close();
fileToUpload.Dispose();
Response res = new Response();
res.Successful = true;
res.Comment = "Bla bla";
return res;
}
And configuration:
<system.serviceModel>
<client>
<endpoint address="" binding="webHttpBinding"
bindingConfiguration="StreamHTTP"
contract="BillboardServices.IBillboardService"
/>
</client>
<bindings>
<webHttpBinding>
<binding name="StreamedHTTP"
transferMode="StreamedRequest"
maxReceivedMessageSize="10000000"
maxBufferSize="1000"
/>
</webHttpBinding>
</bindings>
</system.serviceModel>
When I call the method through Android http request, I get status code 400 – Bad Request.
I have other methods on the same web service, which are working.
I just can’t figure out where the problem is.
I setup a test server, based on the code you have posted above.
I executed the following using Fiddler…
POST http://localhost:3333/upload/step/filename HTTP/1.1
User-Agent: Fiddler
Host: localhost:3333
Content-Length: 11
And on the server I tweaked your code a bit to something like this…
I had no issues.The code ran fine.
Are you sure the URI template you have used is not getting conflicted with some other endpoint perhaps? (usually WebGet)