Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Hwo to post an image to RESTful WCF via WebClient.

Hwo to post an image to RESTful WCF via WebClient.

Scheduled Pinned Locked Moved C#
helpcsharpwcfsysadminjson
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Software2007
    wrote on last edited by
    #1

    I have been wrestling with this for 2 days.:mad: I would like to post a very simple and small 5KB image "myImage.jpg" through my WCF service. I keep getting this error:"The remote server returned an error: (400) Bad Request". I know the problem is with this one method only as all other methods in my service work just fine. This method has a Stream parameter. //Service Code

    //Upload Image
    [OperationContract]
    [WebInvoke(Method = "POST",
    BodyStyle = WebMessageBodyStyle.Bare,
    UriTemplate = "json/UploadImage")]
    void UploadImage(Stream stream);

    void UploadImage(Stream data)
    {
    //Can't seem to get Here Ever!
    }

    //Web.Config

    //Client Code

    //Image file
    WebClient wc = new WebClient();
    // wc.Headers.Add("Content-Type", "octet-stream");
    byte[] rtn = wc.UploadData("http://localhost:2987/GetEmployees.svc/json/Upload", "POST", File.ReadAllBytes("myImage.jpg"));
    Console.WriteLine(System.Text.Encoding.ASCII.GetString(rtn));

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups