Cara mengatasi pengecualian: Server jarak jauh mengembalikan respons yang tidak terduga: (413) Entitas Permintaan Terlalu Besar.

pemrograman

[ad_1]

hai teman-teman… Saya mencoba membuat halaman untuk upload produk menggunakan wcf. Dalam hal ini saya menggunakan perpustakaan layanan.

Tetapi ketika mengklik tombol tambah, itu menunjukkan server jarak jauh melemparkan pengecualian yang disebut
server jarak jauh mengembalikan respons yang tidak terduga: (413) Entitas Permintaan Terlalu Besar.

Apa yang sebenarnya saya lakukan dengan menempatkannya di posting ini adakah yang bisa membantu saya menyelesaikan masalah ini.

tambahkan produk.aspx.cs:

HTML
protected void btnAdd_Click(object sender, EventArgs e)
        {
            
            try
            {
                
                  if (ImageUpload.FileName != "") 
                    {

                        string path = Server.MapPath("~/images/");
                         string extension = Path.GetExtension(ImageUpload.PostedFile.FileName);
                         if (((extension == ".jpg") || ((extension == ".gif") || (extension == ".png"))))

                            {
                             
                               FileStream fs = new FileStream(path+ImageUpload.PostedFile.FileName, FileMode.Open,FileAccess.Read);
                               BinaryReader br = new BinaryReader(fs);
                               byte[] image = br.ReadBytes((int)fs.Length);
                              // byte[] raw = new byte[fs.Length];
                              //fs.Read(raw, 0, Convert.ToInt32(fs.Length));

                               modeldetails.UploadPhoto = image;
                                modeldetails.Serviceno = txtServiceNo.Text;
                                modeldetails.price= long.Parse( txtPrice.Text);
                                modeldetails.Name=txtName.Text;
                                modeldetails.ManfacturedDate=DateTime.Parse(txtManfacDate.Text.ToString());
                                 modeldetails.Manfac_Product_ID=Int32.Parse(ddlProctype.SelectedItem.Value);
                                 bool rows = proxy.AddNewProduct(modeldetails);
                             if (rows)
                                 {
                                     string script = "<script>alert('Data Added Successfully')</script>";
                                     Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Added", script);
                        
                                    }
                             else
                             {
                                 string script = "<script>alert('Error Adding Data')</script>";
                                 Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Error", script);
                               }
                        }
                else
                {
                    StatusLabel.Text = "Only Jpg,gif or Png files are permitted";
                }
            }
            else
            {
                StatusLabel.Text = "Kindly Select a File.....";
            }
           
        }
    
        catch (Exception e1)
        {
 
        }

      }

Perpustakaan Layanan Wcf:

HTML
public bool AddNewProduct(Model modeldetails)
        {
            
            SqlConnection con = new SqlConnection(Properties.Settings.Default.constr);
            con.Open();
            SqlCommand insert = new SqlCommand();
            insert.CommandType = CommandType.StoredProcedure;
            insert.CommandText = "AddProduct";
            insert.Connection = con;
            SqlParameter prm = insert.Parameters.Add("@Modelname", SqlDbType.NVarChar, 50);
            prm.Direction = ParameterDirection.Input;
            prm.Value = modeldetails.Name;
            prm = insert.Parameters.Add("@Price", SqlDbType.BigInt);
            prm.Direction = ParameterDirection.Input;
            prm.Value = modeldetails.price;
            prm = insert.Parameters.Add("@ManfacDate", SqlDbType.DateTime);
            prm.Direction = ParameterDirection.Input;
            prm.Value = modeldetails.ManfacturedDate;
            prm = insert.Parameters.Add("@ServiceNo", SqlDbType.NVarChar, 50);
            prm.Direction = ParameterDirection.Input;
            prm.Value = modeldetails.Serviceno;
            prm = insert.Parameters.Add("@MprocID", SqlDbType.Int);
            prm.Direction = ParameterDirection.Input;
            prm.Value = modeldetails.Manfac_Product_ID;
            prm = insert.Parameters.Add("@Image", SqlDbType.Image);
            prm.Direction = ParameterDirection.Input;
            prm.Value = modeldetails.UploadPhoto;
            



            int insertion_done = insert.ExecuteNonQuery();
            if (insertion_done == 1)
                return true;
            else
                return false;

  
        }

Entitas:

HTML
[DataContract]
    public class Model
    {
        [DataMember]
        public string Name { set; get; }
        [DataMember]
        public string Serviceno { get; set; }
        [DataMember]
        public long price { get; set; }
        [DataMember]
        public byte[] UploadPhoto { set; get; }
        [DataMember]
        public string Configurationdetails { set; get; }
        [DataMember]
        public DateTime ManfacturedDate { set; get; }
        [DataMember]
        public int Manfac_Product_ID { set; get; }


    }
    [DataContract]
    public class Product
    {
        [DataMember]
        public int ProductID
        {
            get;
            set;
        }
        [DataMember]
        public string ProductName
        {
            get;
            set;
        }
        [DataMember]
        public int Manfac_Product_ID
        {
            get;
            set;
        }
    }
    [DataContract]
    public class Manfacture
    {
        [DataMember]
        public int ManfacturerID
        {
            get;
            set;
        }
        [DataMember]
        public string ManfactureName
        {
            get;
            set;
        }

    }


App.config untuk ServiceLibrary:

HTML
<system.servicemodel>
    <bindings>
      <basichttpbinding>
         <binding maxbufferpoolsize="2147483647" maxbuffersize="2147483647" maxreceivedmessagesize="2147483647" messageencoding="Text">
          <readerquotas maxdepth="2000000" maxstringcontentlength="2147483647" maxarraylength="2147483647" maxbytesperread="2147483647" maxnametablecharcount="2147483647" />    
      
        </binding>
      </basichttpbinding>
        
    </bindings>
    <services>
      
      <service name="StoreServiceLibrary.Store">
        
        <endpoint address="" binding="basicHttpBinding" contract="StoreServiceLibrary.IStore">
          
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseaddress="http://localhost:8733/Design_Time_Addresses/StoreServiceLibrary/Service1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <servicebehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the values below to false before deployment -->
          <servicemetadata httpgetenabled="True" httpsgetenabled="True" />
          <!-- 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 -->
          <servicedebug includeexceptiondetailinfaults="False" />
        </behavior>
      </servicebehaviors>
    </behaviors>
  </system.servicemodel>

Solusi 1

Hai,

Anda mengirimkan entitas yang sangat besar atau daftar entitas yang besar ke klien

Bagaimana cara mengatasinya.

XML
<system.servicemodel>
  <bindings>
    <basichttpbinding>
      <binding maxreceivedmessagesize="10485760"> 
        <readerquotas ...="" />
      </binding>
    </basichttpbinding>
  </bindings>  
</system.servicemodel>

Beberapa referensi: http://social.msdn.microsoft.com/Forums/vstudio/en-US/872fff1e-b78e-4b49-808c-558f46a11a17/the-maximum-message-size-quota-for-incoming-messages-65536-has- telah-terlampaui-untuk-meningkatkan-the?forum=wcf[^]

http://stackoverflow.com/questions/5337367/wcf-ws-throwing-maxreceivedmessagessizeexceeded[^]

[ad_2]

コメント

タイトルとURLをコピーしました