尝试在localhost中启动Web服务时,我一直收到此错误:
WCF服务主机找不到任何服务元数据
这是应用程序配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="SrvName" value="..."/>
<add key="DbName" value="..."/>
<add key="DbId" value=".."/>
<add key="DbPw" value=".."/>
<add key="userId" value=".."/>
<add key="userPw" value=".."/>
<add key="code_rep" value=".."/>
<add key="tex_rep" value=""/>
<add key="F_LOG" value="logCla.txt"/>
</appSettings>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="simplecalculmexcomport">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="simplecalculmexcomport" name="WcfsaveRepES.service">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
name="simplecalculhttpservice" contract="WcfsaveRepES.Iservice" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
name="simplecalculmexpservice" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8081/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
有解决方案吗? 谢谢
答案 0 :(得分:0)
我通过将配置添加到我的Console
文件中,在Appconfig
应用程序中对其进行了测试。它正常工作。
服务器端(Console
应用程序,命名空间为ConsoleApp4
)。
class Program
{
static void Main(string[] args)
{
ServiceHost host = new ServiceHost(typeof(Service1));
host.Open();
Console.WriteLine(host.Description.Endpoints[0].Address);
Console.ReadLine();
host.Close();
}
}
[ServiceContract(Namespace ="ABCD")]
public interface IService1
{
[OperationContract]
string GetData(int value);
}
public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}
App.config
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="simplecalculmexcomport">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="simplecalculmexcomport" name="ConsoleApp4.Service1">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
name="simplecalculhttpservice" contract="ConsoleApp4.IService1" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
name="simplecalculmexpservice" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:9099/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
该服务可以正常运行。
您的项目类型是什么?在互联网上搜索了相关的错误之后,该错误似乎主要涉及合格的名称空间问题(服务的Name属性,端点部分的Contract属性)。请参考以下主题。
https://social.msdn.microsoft.com/Forums/vstudio/en-US/ff01e402-3ed4-4cf1-bbbc-2ac22af7fc96/wcf-service-host-cannot-find-any-service-metadata?forum=wcf
Trying to self-host, I get error - wcf service host cannot find any service metadata .. please check if metadata is enabled
WCF service host cannot find any service metadata
请发布完整的代码,我会尽力再现您的问题。随时让我知道问题是否仍然存在。