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

  • Home
  • SEARCH
  • 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 6809653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:06:42+00:00 2026-05-26T20:06:42+00:00

I thought this would be incredibly simple, but I must be missing something. I

  • 0

I thought this would be incredibly simple, but I must be missing something. I am trying to make a simple WCF POST request in conjunction with a UriTemplate. I have read numerous examples where people use a stream paramater as the last paramater, and this is supposed to pick up the POST body. I can only get this to work if the stream is the only paramater.

I’ve gone back to basics with a simple Hello World service.

Here is my code on the client

static string Test()
{
    HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://localhost:1884/MyAPI/Service.svc/HelloWorld");
    req.Method = "POST";
    req.ContentType = "text/plain";
    Stream reqStream = req.GetRequestStream();
    byte[] fileToSend = System.Text.UTF8Encoding.UTF8.GetBytes("sometext");
    reqStream.Write(fileToSend, 0, fileToSend.Length);
    reqStream.Close();
    HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
    var sr = new StreamReader(resp.GetResponseStream());
    return sr.ReadToEnd();
}

And this is the code on the service

[ServiceContract]
public interface IService
{
    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "HelloWorld")]
    Stream HelloWorld(Stream content);
}

public Stream HelloWorld(Stream content)
{
    var sr = new StreamReader(content);
    string text = sr.ReadToEnd();
    return new System.IO.MemoryStream(Encoding.UTF8.GetBytes("Hello World! " + text)); 
}

This all works fine. Then I make this change:

[ServiceContract]
public interface IService
{
    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "HelloWorld/test/{test}")]
    Stream HelloWorld(string test, Stream content);
}

public Stream HelloWorld(string test, Stream content)
{
    var sr = new StreamReader(content);
    string text = sr.ReadToEnd();
    return new System.IO.MemoryStream(Encoding.UTF8.GetBytes("Hello World! " + text + test)); 
}

And change the client code to hit HelloWorld/test/sometext

I get a 500 Internal Server Error. I’ve tried about 10 different variations including using a ?key=value type UriTemplate, returning strings instead of streams etc, and no luck.

Feels like I’m missing some tiny little thing that is going to make this work, as I have seen countless examples of exactly this all over the web. Theirs works, mine doesn’t.

Any ideas?

  • 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-05-26T20:06:42+00:00Added an answer on May 26, 2026 at 8:06 pm

    I am not sure what went wrong, but after trying everything, I resolved this by creating a new project and copying all the code over. Never worked out what the differences were, maybe something got corrupted

    Edit: in the end we discovered we had to specify WebServiceHostFactory in the Service.svc. This was there by default in the new project

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought this would be simple, but I can't see how to tell WCF
Hey guys, I thought this would be an incredibly simple thing to do, but
I thought this would be a relatively simple task with something like FMOD, but
I thought this would be simple, but its not working .. in both the
I thought this would be really simple but .. We've create a user and
I thought this would be simple, but for my life, I can't change the
I thought this would be simple, but I'm struggling (might be Friday brains) I
I thought this would be something that's fairly common - but cant find it
I thought this would be simple, but searching Google didn't seem to help. I'm
I thought this would be fairly easy, but I'm totally baffled. I want one

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.