【发布时间】:2011-10-15 15:59:33
【问题描述】:
我有以下合同:
[OperationContract(Name = "Upload")]
[WebInvoke(Method = "POST", UriTemplate = "/Upload/{step}/{fileName}",
BodyStyle= WebMessageBodyStyle.WrappedRequest)]
Response FileUpload(string fileName, string step, Stream fileStream);
以及实现:
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;
}
及配置:
<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>
当我通过 Android http 请求调用该方法时,我得到状态码 400 - Bad Request。 我在同一个 Web 服务上有其他方法,它们正在工作。 我就是不知道问题出在哪里。
【问题讨论】:
-
使用 Wireshark 检查实际有线流量。
-
感谢您的想法。我在 Android 端和服务器端都试过了,它看起来就像一个普通的多部分帖子。我不是一个大网络奇才,但对我来说看起来不错。