Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I get my default RESTful WCF service to support VARBINARY data so that larger documents can be transported?
    primarykey
    data
    text
    <p>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:</p> <blockquote> <p>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.</p> </blockquote> <p>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:</p> <pre><code>&lt;%@ ServiceHost Language="C#" Debug="true" Service="MyProject.MyService" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %&gt; </code></pre> <p>The code behind for my service looks like this:</p> <pre><code>[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; } } </code></pre> <p>Doc is a custom class that looks like this:</p> <pre><code>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; } } } </code></pre> <p>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.</p> <pre><code>public class MyClient { WebChannelFactory&lt;IMyService&gt; cf; IMyService channel; public MyClient() { cf = new WebChannelFactory&lt;IMyService&gt;(new Uri("http://www.something.com/myservice.svc")); channel = cf.CreateChannel(); } public Doc GetDoc(string docid) { return channel.GetDoc(docid); } } </code></pre> <p>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?</p> <p>I looked at this question and tried to do what it recommends but it didn't work. <a href="https://stackoverflow.com/questions/4083758/wcf-webservicehostfactory-maxreceivedmessagesize-configuration">WCF WebServiceHostFactory MaxReceivedMessageSize configuration</a></p> <p>Any help is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload