当超过48765字节时,将图像作为字节[]从silverlight发送到WCF失败
我正在尝试将图像从silverlight客户端发送到WCF服务 我有以下课程要送当超过48765字节时,将图像作为字节[]从silverlight发送到WCF失败,silverlight,wcf,soap,Silverlight,Wcf,Soap,我正在尝试将图像从silverlight客户端发送到WCF服务 我有以下课程要送 namespace PhotoViewer.DataObjects.Requests { public class SavePhotoRequest { public Photo Photo { get; set; } } } namespace PhotoViewer.DataObjects.Entitys { public class Photo {
namespace PhotoViewer.DataObjects.Requests
{
public class SavePhotoRequest
{
public Photo Photo { get; set; }
}
}
namespace PhotoViewer.DataObjects.Entitys
{
public class Photo
{
public Photo() { }
public Photo(int id, DateTime takeOn, Byte[] photoBinary)
{
_iD = id;
_takenOn = takeOn;
_photoBinary = photoBinary;
}
int _iD;
DateTime _takenOn;
Byte[] _photoBinary;
public int ID { get { return _iD; } set { _iD = value; } }
public DateTime TakeOn { get { return _takenOn; } set { _takenOn = value; } }
public Byte[] PhotoBinary { get { return _photoBinary; } set { _photoBinary = value; } }
}
}
我已经尝试在我的配置文件中将所有内容设置为max,如下所示
ServiceReference.ClientConfig
Web.Config
但一旦字节数组超过48765,它就无法工作。我从fiddler那里得到了以下回应
HTTP/1.1 400错误请求服务器:
ASP.NET开发服务器/10.0.0.0
日期:2011年4月8日星期五21:58:57 GMT
X-AspNet-Version:4.0.30319
缓存控制:专用内容长度:
0连接:关闭
我读过很多文章,其中似乎只增加配置文件中的所有大小就可以了,但我已经将这些都设置为最大值,无法找出我遗漏了什么
编辑
这里是PhotoService.svc
<%@ ServiceHost Language="C#"
Debug="true"
Service="PhotoViewer.Service.Implementations.PhotoService" %>
和PhotoService.cs
namespace PhotoViewer.Service.Implementations
{
public class PhotoService : IPhotoService
{
IUnityContainer container;
public PhotoService()
{
SetUnityContainer();
}
public SavePhotoResult SavePhoto(SavePhotoRequest request)
{
var imageRepository = container.Resolve<IPhotoRepository>();
imageRepository.SavePhoto(request.Photo);
container.Resolve<IUnitOfWork>().SubmitChanges();
return new SavePhotoResult();
}
private void SetUnityContainer()
{
container = new UnityContainer();
container.RegisterType<IUnitOfWork, DatabaseUnitOfWork>(new ContainerControlledLifetimeManager());
container.RegisterType<IRepository<Photo>, Repository<Photo>>(new ContainerControlledLifetimeManager());
container.RegisterType<IPhotoRepository, PhotoRepository>(new ContainerControlledLifetimeManager());
}
}
哦,多尴尬啊,看来我只是个十足的裸体 不知怎的,我在项目中得到了一个web.config文件,其中包含了我的服务接口和实现。我一直在更改此配置文件中的所有设置,而不是asp.net宿主项目中使用的配置文件 当我把设置从错误的配置文件复制到正确的配置文件时,一切都正常了!!
是的,有时候最好不要开夜车你能发布PhotoService.svc和PhotoService.svc.cs的内容吗?你尝试过流模式吗?我确实想到了,因为我认为你不能将ClientConfig文件设置为使用transferMode=Streamed。。除非我遗漏了什么似乎是这里的错误:。我也会增加这个值。我试着用默认设置从WCF服务读取和显示一个图像,它可以工作。可能是因为我在本地IIS上部署了服务。
<%@ ServiceHost Language="C#"
Debug="true"
Service="PhotoViewer.Service.Implementations.PhotoService" %>
namespace PhotoViewer.Service.Implementations
{
public class PhotoService : IPhotoService
{
IUnityContainer container;
public PhotoService()
{
SetUnityContainer();
}
public SavePhotoResult SavePhoto(SavePhotoRequest request)
{
var imageRepository = container.Resolve<IPhotoRepository>();
imageRepository.SavePhoto(request.Photo);
container.Resolve<IUnitOfWork>().SubmitChanges();
return new SavePhotoResult();
}
private void SetUnityContainer()
{
container = new UnityContainer();
container.RegisterType<IUnitOfWork, DatabaseUnitOfWork>(new ContainerControlledLifetimeManager());
container.RegisterType<IRepository<Photo>, Repository<Photo>>(new ContainerControlledLifetimeManager());
container.RegisterType<IPhotoRepository, PhotoRepository>(new ContainerControlledLifetimeManager());
}
}