简体   繁体   中英

How to start a WCF service outside Visual Studio?

I just created a WCF service with this MSDN tutorial .

  • from within Visual studio I can CTRL-F5 the service so it is running
  • then I can start my Console Application Client and consume the service no problem

Now I want to start my service OUTSIDE visual studio and have various clients consume it.

But when I go to the command line and execute this file ../bin/Debug/testService.exe, I get an exception: " Input has the wrong format ".

I get the same error when I publish the service and start the published .exe file.

What am I missing here? Do I need to send some kind of parameter that Visual Studio is sending to make it run?

How can I run my WCF service externally outside Visual Studio?

Without seeing your code and config files it is difficult to work out why your getting this problem, but setting up a WCF service correctly can be a little tricky at first.

I recommend checking out the endpoint.TV screencasts on WCF and in particular the self hosting WCF services screencast.

They are easy to follow and will explain enough to get you started.

Uri baseAddress = new Uri("http://localhost:8080/hello");

// Create the ServiceHost.
using (ServiceHost host = new ServiceHost(typeof(HelloWorldService), baseAddress))
{
    // Enable metadata publishing.
    ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
    smb.HttpGetEnabled = true;
    smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
    host.Description.Behaviors.Add(smb);

    // Open the ServiceHost to start listening for messages. Since
    // no endpoints are explicitly configured, the runtime will create
    // one endpoint per base address for each service contract implemented
    // by the service.
    host.Open();

    Console.WriteLine("The service is ready at {0}", baseAddress);
    Console.WriteLine("Press <Enter> to stop the service.");
    Console.ReadLine();

    // Close the ServiceHost.
    host.Close();
}

http://msdn.microsoft.com/en-us/library/ms731758%28v=vs.110%29.aspx

For me, the easiest way to show someone how to get a WCF app up and running so you can learn is to create it all manually, eschewing the VS2008 built in tools. Here's an excellent tutorial that shows you what to do:

WCF the Manual Way - the Right Way

I wrote an article expanding on that article a little bit over on my blog post. I included sourcefiles as well as a screencast. You can find it here:

Manual WCF - An Extension

Also, an excellent series of tutorials can be found in Michele Bustamante's Learning WCF . It's a bit dated, focusing on .NET 3.0, but most of the examples still work and she's updated her source on her blog.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM