我有以下合约:文件流媒体从安卓到WCF
[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 - 错误的请求。 我有相同的Web服务的其他方法,这是工作。 我只是想不通问题出在哪里。
使用Wireshark来检查*实际*线路流量。 – Amy
感谢您的想法。我在Android端和服务器端都尝试过它,它看起来像一个普通的多部分帖子。我不是一个大型的网络专家,但对我来说看起来很好。 –