我新的WCF編程,我也跟着系列入門教程從下面的鏈接WCF與Visual Studio 2012
http://msdn.microsoft.com/en-us/library/ms734712.aspx
我在控制檯應用程序託管服務,但是當我試圖創建一個客戶端和試圖添加服務參考我有以下例外。託管應用
class Program
{
static void Main(string[] args)
{
// Step 1 Create a URI to serve as the base address.
Uri baseAddress =
new Uri("http://localhost:8000/GettingStarted/");
// Step 2 Create a ServiceHost instance
ServiceHost selfHost =
new ServiceHost(typeof(CalculatorService), baseAddress);
try
{
// Step 3 Add a service endpoint.
selfHost.AddServiceEndpoint(typeof(ICalculator),
new WSHttpBinding(),
"CalculatorService");
// Step 4 Enable metadata exchange.
var smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
// Step 5 Start the service.
selfHost.Open();
Console.WriteLine("The service is ready.");
Console.WriteLine("Press <ENTER> to terminate.");
Console.WriteLine();
Console.ReadLine();
// Close the ServiceHostBase to shutdown.
selfHost.Close();
}
catch (CommunicationException ce)
{
Console.WriteLine("exception: {0}", ce.Message);
selfHost.Abort();
}
}
}
的
There was an error downloading 'http: localhost:8000/GettingStarted/mex/_vti_bin/ListData.svc/$metadata'. The request failed with HTTP status 405: Method Not Allowed. Metadata contains a reference that cannot be resolved: 'http: localhost:8000/GettingStarted/mex'. There was no endpoint listening at http: localhost:8000/GettingStarted/mex that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. The remote server returned an error: (404) Not Found. If the service is defined in the current solution, try building the solution and adding the service reference again.
代碼現在我無法弄清楚的問題是什麼。我正在使用visual studio 2012和.net平臺4.5。
首先您是否能夠成功託管一項服務?你能分享你的控制檯應用程序的輸出嗎? – Praburaj