Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8799503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:20:28+00:00 2026-06-14T00:20:28+00:00

i am trying to post an image to wcf rest service from silverlight 4

  • 0

i am trying to post an image to wcf rest service from silverlight 4 but i am getting an exception when i am taking resonse from the request, the exception is

System.Net.WebException: The remote server returned an error: NotFound. —> System.Net.WebException: The remote server returned an error: NotFound.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.BrowserHttpWebRequest.<>c_DisplayClassa.b_9(Object sendState)
at System.Net.Browser.AsyncHelper.<>c_DisplayClass4.b_1(Object sendState)
— End of inner exception stack trace —
at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at Admin.Popups.AddCategory.OnImageGetResponseCompleted(IAsyncResult ar)}

all of my other functions on the service is working fine even this one when i try to access it from android, i already had a look and tried the silverlight cross domain policy but i dont think its applicable, my code is below

private void UpLoadImage()
        {
            string URL = Utilities.GetServiceUrl() + "AddCategoryImage?CategoryId=2&ContentType=image&apikey=" + Utilities.GetApiKey();
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
            request.Method = "POST";
            request.ContentType = "text/plain";
            request.ContentLength = SelectedFile.Length;

            request.BeginGetRequestStream(OnImageGetRequestStreamCompleted, request);
        }

        private void OnImageGetRequestStreamCompleted(IAsyncResult ar)
        {
            try
            {
                if (SelectedFile != null)
                {
                    HttpWebRequest request = (HttpWebRequest)ar.AsyncState;

                    using (Stream postStream = request.EndGetRequestStream(ar))
                    {
                        using (Stream source = SelectedFile.OpenRead())
                        {
                            byte[] buffer = new byte[2048];
                            int bytesRead;
                            while ((bytesRead = source.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                postStream.Write(buffer, 0, bytesRead);
                            }
                        }

                   }

                    request.BeginGetResponse(new AsyncCallback(OnImageGetResponseCompleted), request);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void OnImageGetResponseCompleted(IAsyncResult ar)
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)ar.AsyncState;
                HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(ar);
                using (StreamReader sr = new StreamReader(response.GetResponseStream()))
                {
                    string result = sr.ReadToEnd();
                }
            }
            catch (Exception ex)
            {
                this.Dispatcher.BeginInvoke(delegate()
                        {
                            MessageBox.Show(ex.Message);
                        });
            }
        }

the wcf function is

[OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "AddCategoryImage?CategoryId={CategoryId}&ContentType={ContentType}", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
        bool AddCategoryImage(int CategoryId, string ContentType, Stream Image);

and function implementation is

 public static bool AddCategoryImage(int CategoryId, string ContentType,Stream Image)
        {
            SqlConnection sqlCon = new SqlConnection(Params.GetConnectionString());
            SqlCommand sqlCmd = new SqlCommand("UPDATE Categories SET Cat_Img = @Cat_Img,Cat_Img_Type = @Cat_Img_Type WHERE Cat_ID = @Cat_ID", sqlCon);
            sqlCmd.Parameters.Add("@Cat_Img", SqlDbType.Image).Value = Utility.ConvertStreamToByteArray(Image);
            sqlCmd.Parameters.Add("@Cat_Img_Type", SqlDbType.NVarChar, 32).Value = ContentType;
            sqlCmd.Parameters.Add("@Cat_ID", SqlDbType.Int).Value = CategoryId;

            try
            {
                sqlCon.Open();

                return sqlCmd.ExecuteNonQuery() > 0 ? true : false;
            }
            catch (Exception ex)
            {
                Error.CreateError(ex.Message, "Category.cs", "AddCategoryImg(int,string,Stream)");
            }
            finally
            {
                sqlCon.Close();
            }

            return false;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:20:31+00:00Added an answer on June 14, 2026 at 12:20 am

    i have solved the issue WCF defualt maxReceivedMessageSize is 65K and i was trying to upload file more than 65k, clever me 🙂 so i set the maxReceivedMessageSize=”2000000″ to 2MB now it works for files up to 2MB

    <binding name ="webBinding" sendTimeout="00:10:00" receiveTimeout="00:10:00" openTimeout="00:10:00"  closeTimeout="00:10:00" maxReceivedMessageSize="2000000">
        <readerQuotas maxDepth="32" maxStringContentLength="100000000" maxArrayLength="100000000" maxBytesPerRead="100000000" maxNameTableCharCount="100000000" />
    </binding>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WCF restful service that I'm trying to upload an image to.
I am trying to use this answer from an old post: Display image from
I'm trying to post an image from an iphone app to a .Net webservice
I'm trying to post a photo using mikeal request library, but the post comes
I am trying to post image on facebook but not successful yet, my codes
I'm trying to POST an image (with Metadata) to Picasa Webalbums from within a
I am trying to post an image to Facebook. Yesterday i got it, but
I am trying to post an image to a Facebook album using a form
I am trying to receive the url image and post the image into base64
I'm trying to convert the following CURL: curl -X POST \ -H Content-Type: image/jpeg

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.