I have a RESTful WCF service that is working fine. Now I have a need to store binary information (PDF documents) in the back end SQL Server database. So now my service needs to be able to transport VARBINARY data - I suppose as a byte array. When I set this up and try to get it working I receive the following error:
The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.
The only problem is that I don't have any binding elements set up in my Web.config. I am using the default WebServiceHostFactory in my .SVC file. It looks like this:
<%@ ServiceHost Language="C#" Debug="true" Service="MyProject.MyService" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
The code behind for my service looks like this:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceContract]
public class MyService
{
public MyService()
{
XmlConfigurator.Configure();
}
[WebGet(UriTemplate = "/docs/{docid}")]
[OperationContract]
public Doc GetDoc(string docid)
{
[do some stuff to get a Doc object that has the byte array with the PDF file]
return _doc;
}
}
Doc is a custom class that looks like this:
public class Doc
{
private string _title;
private DateTime _docDate;
private byte[] _pdfFile;
public string Title
{
get{ return _title; }
set{ _title = value; }
}
public DateTime DocDate
{
get{ return _docDate; }
set{ _docDate = value; }
}
public byte[] PDFFile
{
get{ return _pdfFile; }
set{ _pdfFile = value; }
}
}
On the client side of things I have the following code that accesses the service. Again there is nothing in the Web.config at all. I am using the Factory.
public class MyClient
{
WebChannelFactory<IMyService> cf;
IMyService channel;
public MyClient()
{
cf = new WebChannelFactory<IMyService>(new Uri("http://www.something.com/myservice.svc"));
channel = cf.CreateChannel();
}
public Doc GetDoc(string docid)
{
return channel.GetDoc(docid);
}
}
Everything that I have read talks about making Web.config changes on both the client and the service to allow for a larger message size. But since I am using the Factory on both the client and the service I don't think that will work. Is there some way in code that I can modify my setup to allow for a larger message size?
I looked at this question and tried to do what it recommends but it didn't work. WCF WebServiceHostFactory MaxReceivedMessageSize configuration
Any help is appreciated.