Post 图片从 android 到 WCF Rest 服务,并以图片形式返回响应
Post Image from android to WCF Rest service and Get response back as image
我需要 post 一个 Image 到 wcf 服务,服务将对图像和响应返回图像执行一些操作.怎么做?我需要双方的帮助 android 和 wcf
是的,这很容易,只要您接受并返回 Stream
并使用 WebHttpBinding
。参见 Can a WCF REST endpoint be forced to accept Raw message format? and How to: Create a Service That Returns Arbitrary Data Using The WCF Web HTTP Programming Model
基本如下:
[WebInvoke(Method = "POST", UriTemplate = "processImage")]
public Stream ProcessImage(Stream inputImage)
{
// do stuff with inputImage
WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
return /* some stream with jpeg data */;
}
从客户端,您只是发布一个 HTTP 请求。参见 but use the resultant HttpResponse
to access the returned image。
我需要 post 一个 Image 到 wcf 服务,服务将对图像和响应返回图像执行一些操作.怎么做?我需要双方的帮助 android 和 wcf
是的,这很容易,只要您接受并返回 Stream
并使用 WebHttpBinding
。参见 Can a WCF REST endpoint be forced to accept Raw message format? and How to: Create a Service That Returns Arbitrary Data Using The WCF Web HTTP Programming Model
基本如下:
[WebInvoke(Method = "POST", UriTemplate = "processImage")]
public Stream ProcessImage(Stream inputImage)
{
// do stuff with inputImage
WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg";
return /* some stream with jpeg data */;
}
从客户端,您只是发布一个 HTTP 请求。参见 but use the resultant HttpResponse
to access the returned image。