Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Save file using WCF service
    primarykey
    data
    text
    <p>I am using WCF for upload a file in data base(C#) and i got this error. the remote server returned an unexpected response (413) request entity too large.</p> <p>Code in IService.cs</p> <pre><code>[OperationContract] void UploadFile(RemoteFileInfo request); </code></pre> <p>[MessageContract] public class DownloadRequest { [MessageBodyMember] public string FileName; }</p> <pre><code>[MessageContract] public class RemoteFileInfo : IDisposable { [MessageHeader(MustUnderstand = true)] public string FileName; [MessageHeader(MustUnderstand = true)] public int ItemID; [MessageHeader(MustUnderstand = true)] public string FileExt; [MessageBodyMember(Order = 1)] public System.IO.Stream FileByteStream; public void Dispose() { if (FileByteStream != null) { FileByteStream.Close(); FileByteStream = null; } } </code></pre> <p>Code in Service.svc.cs</p> <pre><code> public void UploadFile(RemoteFileInfo request) { AttachmentDTO objDTO = new AttachmentDTO(); //FileStream targetStream = null; Stream stream = request.FileByteStream; const int bufferLen = 65000; // byte[] buffer = new byte[bufferLen]; // objDTO.FileData = buffer; AttachmentBLL objBLL = new AttachmentBLL(); try { byte[] readBuffer = new byte[bufferLen]; int totalBytesRead = 0; int bytesRead; while ((bytesRead = stream.Read(readBuffer, totalBytesRead, readBuffer.Length - totalBytesRead)) &gt; 0) { totalBytesRead += bytesRead; if (totalBytesRead == readBuffer.Length) { int nextByte = stream.ReadByte(); if (nextByte != -1) { byte[] temp = new byte[readBuffer.Length * 2]; Buffer.BlockCopy(readBuffer, 0, temp, 0, readBuffer.Length); Buffer.SetByte(temp, totalBytesRead, (byte)nextByte); readBuffer = temp; totalBytesRead++; } } } byte[] buffer = readBuffer; if (readBuffer.Length != totalBytesRead) { buffer = new byte[totalBytesRead]; Buffer.BlockCopy(readBuffer, 0, buffer, 0, totalBytesRead); } objDTO.FileData = buffer; objDTO.FileName = request.FileName; objDTO.CreatedDate = DateTime.Now; objDTO.CreatedBy = "user"; objDTO.IsActive = true; objDTO.FileExt = request.FileExt; objBLL.AddAttachment(objDTO); } catch (Exception ex) { } } </code></pre> <p>objBLL.AddAttachment(objDTO); this method is in business logic file. BLL can communicate with DAL but DAL Can't Communicate with WCF Service.</p> <pre><code> This Code is written in page.aspx.cs file. if (fuAttachment.HasFile) { string abs = fuAttachment.PostedFile.FileName; System.IO.FileInfo fileInfo = new System.IO.FileInfo(fuAttachment.PostedFile.FileName); MyService.RemoteFileInfo uploadRequestInfo = new MyService.RemoteFileInfo(); using (System.IO.FileStream stream = new System.IO.FileStream(fuAttachment.PostedFile.FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { uploadRequestInfo.FileName = fuAttachment.FileName; uploadRequestInfo.Length = fileInfo.Length; uploadRequestInfo.FileByteStream = fuAttachment.FileContent; uploadRequestInfo.ItemID = itemId; uploadRequestInfo.FileExt = fuAttachment.PostedFile.ContentType; client.UploadFile(uploadRequestInfo.FileExt, uploadRequestInfo.FileName, uploadRequestInfo.ItemID, uploadRequestInfo.FileByteStream); } } </code></pre> <p>web.config</p> <pre><code>&lt;binding name="WSHttpBinding_IEMRProWCFService" closeTimeout="04:01:00" openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"&gt; &lt;readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /&gt; &lt;reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /&gt; &lt;security mode="None"&gt; &lt;transport clientCredentialType="None" proxyCredentialType="None" realm="" /&gt; &lt;message clientCredentialType="UserName" algorithmSuite="Default" /&gt; &lt;/security&gt; &lt;/binding&gt; </code></pre> <p>and Service .config</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;configuration&gt; &lt;system.web&gt; &lt;compilation debug="true" /&gt; &lt;httpRuntime maxRequestLength="2147483647" /&gt; &lt;/system.web&gt; &lt;system.serviceModel&gt; &lt;services&gt; &lt;service name="WCFService.EMRProWCFService"&gt; &lt;endpoint address="" binding="wsHttpBinding" contract="WCFService.IEMRProWCFService"&gt; &lt;identity&gt; &lt;dns value="localhost" /&gt; &lt;/identity&gt; &lt;/endpoint&gt; &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&gt; &lt;/service&gt; &lt;/services&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior&gt; &lt;!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --&gt; &lt;serviceMetadata httpGetEnabled="true" /&gt; &lt;!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --&gt; &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;/behaviors&gt; &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" /&gt; &lt;bindings&gt; &lt;webHttpBinding&gt; &lt;binding name="WebConfiguration" maxBufferSize="65536" maxReceivedMessageSize="2147483647" transferMode="Streamed"&gt; &lt;/binding&gt; &lt;/webHttpBinding&gt; &lt;/bindings&gt; &lt;/system.serviceModel&gt; &lt;system.webServer&gt; &lt;modules runAllManagedModulesForAllRequests="true" /&gt; &lt;directoryBrowse enabled="true" /&gt; &lt;/system.webServer&gt; &lt;/configuration&gt; </code></pre> <p>Can any one help me where i made mistake... Thanks</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.
 

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