![](/img/trans.png)
[英]Could not find a base address that matches scheme net.tcp for the endpoint
[英]Could not find a base address that matches scheme net.tcp for the endpoint with binding MetadataExchangeTcpBinding self hosting
我创建了一个具有Datacontract和服务合约及其实现的类库。 然后,我创建了一个控制台应用程序来托管wcf服务。 我在下面的app.config文件中定义了WCF设置。 <configuration> <system.serviceModel> <services> <service name="TestService.TestService" behaviorConfiguration="tcpbindingConfiguration"> <host> <baseAddresses> <add baseAddress="net:tcp://FullComputerName:9002/TestService"/> </baseAddresses> </host> <endpoint address="net:tcp://FullComputerName:9002/TestService" binding="netTcpBinding" contract="TestService.ITestServiceContract"></endpoint> <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"></endpoint> </service> </services> <behaviors> <serviceBehaviors> <behavior name="tcpbindingConfiguration"> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> </startup> </configuration>
然后我编制了program.cs文件。
ServiceHost sh = null;
try
{
sh = new ServiceHost(typeof(TestService.TestService));
sh.Open();
Console.WriteLine("Service started at net:tcp//FullComputerName:9002/TestService");
}
catch (Exception ex)
{
sh = null;
Console.WriteLine("Service cann't started");
throw;
}
我已经从Windows功能的开和关激活了WCF for Non HTTP。
我想在控制台应用程序中托管此wcf服务,有些文章建议我需要在IIS中设置nettcp绑定。 我为什么要这么做?
IIS是WCF服务的替代宿主,即您可以将其宿主在控制台应用程序中或IIS中。 据我了解,如果使用控制台应用程序,则无需设置IIS。
尝试将配置中的“ net:tcp”更改为“ net.tcp”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.