0
我試圖創建一個基本的WCF應用程序,但是當我運行它,我得到一個錯誤:WCF錯誤「具有零的應用程序(非基礎設施)端點」
這是服務:
namespace WcfTranslationLibrary
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface ITranslationService
{
[OperationContract]
string Translate(string value);
// TODO: Add your service operations here
}
}
這是我的課:
namespace WcfTranslationLibrary
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
public class PigLatinTranslator : ITranslationService
{
public string Translate(string value)
{
return string.Format("You entered: {0}", value);
}
}
}
這是我App.config文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="WcfTranslationLibrary.PigLatinTranslator">
<endpoint address="" binding="basicHttpBinding" contract="WcfTranslationLibrary.ITranslationService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/WcfTranslationLibrary/PigLatinTranslator/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
,這是控制檯應用程序,我使用:
namespace ServiceHostConsoleApp
{
class Program
{
static void Main(string[] args)
{
ServiceHost myHost = new ServiceHost(typeof(PigLatinTranslator));
myHost.Open();
Console.WriteLine("Translator running...");
Console.ReadLine();
myHost.Close();
}
}
}
任何想法?