我有一个非常简单的DTO返回图像:从一个RESTful WCF服务
[DataContract]
public class DTO
{
[DataMember]
public byte[] Image {get; set; }
}
而这个非常简单的服务:
[ServiceContract]
public interface IFooService
{
[WebGet(
UriTemplate = "",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json)]
List<DTO> GetDTOs();
}
在我的Global.asax,我有:
RouteTable.Routes.Add(new ServiceRoute("foo",
new WebServiceHostFactory(), typeof(FooService)));
现在,当我从浏览器调用此函数时,我得到的是JSON格式的字节数组。目前很好。现在,我该如何将这些字节数组转换为图像?
或者,有没有更好的方法去做这件事?我试着将byte[]
更改为Stream
,但是当我从Firefox调用服务时,尽管HTTP状态码为200,响应仍为空。我正在使用Firebug和Fiddler。
我不认为这是相关的,但由于太多的信息从来没有伤害过任何人谁是不是机器人,这里的web.config中:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
</system.webServer>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
</configuration>
最后,我想这个问题是:如何做你从WCF RESTful服务返回一个位图,所以在浏览器中运行的JavaScript可以把它放在屏幕上?
我无法理解这里投票的逻辑。 –