For asking and answering questions on Stack Overflow with certain frameworks and libraries I have boilerplate lying around for a minimal repro. I would be interested in getting feedback on my WCF basic minimal repro, because I want to make sure it will be up to snuff.
I want to be a good CodeReview.SE citizen, but in the past I've had problems determining what is considered good practice / on-topic here. So I figured this time, because I'm blurry on this one, I'd ask for advice beforehand.
I've read the FAQ, and from that I found (highlights mine) that these are required:
- Is code included directly in my question?
- Am I an owner or maintainer of the code?
- Is it actual code from a project rather than pseudo-code or example code?
- Do I want the code to be good code? (i.e. not code-golfing, obfuscation, or similar)
- To the best of my knowledge, does the code work as intended?
- Do I want feedback about any or all facets of the code?
Most boxes I think I'd tick off, except the highlighted parts, I'm not sure about those.
Would anyone be so kind as to clarify if "code for an exemplary minimal WCF repro" is off-topic as it's "example code", or whether I'm taking the FAQ text too literally?
I'm not sure if it's helpful or frowned upon, but with the best of intentions, here is the code I'd be asking a review for:
using System; using System.ServiceModel; using System.ServiceModel.Description; using System.Threading.Tasks; namespace WcfMinimalTest { // WARNING! This minimal repro does no cleanup or error handling whatsoever!! // Loosely based on http://stackoverflow.com/a/7833188/419956 by @Anuraj public class Program { static void Main() { Task.Run(() => Host()); var client = new FooProxy(); var result = client.Bar(); Console.WriteLine($"Received result from service via proxy: {result}"); Console.WriteLine("Press any key to exit."); Console.ReadKey(); } static void Host() { Console.WriteLine("Service starting..."); var host = new ServiceHost(typeof(FooService), new Uri("net.pipe://localhost/")); host.AddServiceEndpoint(typeof(IFooService), new NetNamedPipeBinding(), "fooservice"); host.Open(); Console.WriteLine("Service started."); } } [ServiceContract] public interface IFooService { [OperationContract] string Bar(); } public class FooService : IFooService { public string Bar() { Console.WriteLine($"Service {nameof(Bar)}"); return "Barrrr, matey!"; } } public class FooProxy : ClientBase<IFooService> { public FooProxy() : base (new ServiceEndpoint(ContractDescription.GetContract( typeof(IFooService)), new NetNamedPipeBinding(), new EndpointAddress("net.pipe://localhost/fooservice"))) { } public string Bar() { Console.WriteLine($"Proxy {nameof(Bar)}"); return Channel.Bar(); } } }
FooProxy
,FooService
,Bar
? Also, you may be interested in this answer. \$\endgroup\$FooProxy
, if I'm answering questions on SO. It is intentionally abstract. It is also in a sense "real" code, that I'd use to answer a question. The thing is that others might grab my code, replace "Foo" with their own names, and carry on with the code (which is why it seemed important to have "correct" abstract repros). - (I'll read through the link you gave too, thx.) \$\endgroup\$