我正在尝试将图像从silverlight客户端发送到WCF服务。
我有以下要发送的课程
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
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding
name="BasicHttpBinding_IPhotoService"
closeTimeout="10:00:00"
openTimeout="10:00:00"
receiveTimeout="10:00:00"
sendTimeout="10:00:00"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647"
textEncoding="utf-8"
transferMode="Buffered">
<security mode="None">
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:52715/PhotoService.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IPhotoService"
contract="PhotoViewer.Model.ServiceContracts.IPhotoService"
name="BasicHttpBinding_IPhotoService" />
</client>
</system.serviceModel>
</configuration>
的Web.Config
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime maxRequestLength="102400"/>
</system.web>
<system.serviceModel>
<services>
<service name="PhotoViewer.Service.Implementations.PhotoService"
behaviorConfiguration="PhotoDebugBehaviors">
<endpoint contract="PhotoViewer.Service.Interfaces.IPhotoService"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IPivotService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="PhotoDebugBehaviors">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<bindings>
<basicHttpBinding>
<binding
name="BasicHttpBinding_IPivotService"
closeTimeout="10:00:00"
openTimeout="10:00:00"
receiveTimeout="10:00:00"
sendTimeout="10:00:00"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647"
maxBufferPoolSize="2147483647"
textEncoding="utf-8" >
<readerQuotas maxArrayLength="2147483647"
maxStringContentLength="2147483647"
maxBytesPerRead="2147483647"
maxDepth="2147483647"
maxNameTableCharCount="2147483647"
/>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
但是,只要Bytes数组超过48765,它就不会起作用。我从fiddler得到以下回复。
HTTP / 1.1 400错误请求服务器: ASP.NET Development Server / 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());
}
}
答案 0 :(得分:0)
哦,多么尴尬,似乎我只是一个完全Numpty!
不知怎的,我在项目中得到了一个包含我的服务接口和实现的web.config文件。我一直在更改此配置文件中的所有设置,而不是在asp.net托管项目中使用的配置文件。
一旦我将设置从错误的配置复制到正确的配置文件,它一切正常! 是的,有时最好不要燃烧午夜的油