我刚刚开始学习wcf,目前已经走到了这一步。
CS文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace wcfLib
{
[ServiceContract]
public interface IfaceService
{
[OperationContract]
int wordLen(string word);
}
public class StockService : IfaceService
{
public int wordLen(string word)
{
return word.Length;
}
}
}然而,当我试图运行它时,它弹出一个错误:
WCF服务主机找不到任何服务元数据...
知道可能是什么吗?
配置文件:
<system.serviceModel>
<services>
<service behaviorConfiguration="wcfLib.Service1Behavior" name="wcfLib.Service1">
<endpoint address="" binding="wsHttpBinding" contract="wcfLib.ser">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/wcfLib/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="wcfLib.Service1Behavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>发布于 2011-03-07 23:49:36
您的配置文件中需要包含以下内容:
1)元数据的服务行为:
<behaviors>
<serviceBehaviors>
<behavior name="Metadata">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>2)在服务配置中引用服务行为
<service name="wcfLib.StockService"
behaviorConfiguration="Metadata">
....
</service>*配置文件中服务标签中的名称值必须与实现合同的物理类同名。请记住,如果类名发生更改,请确保更改此值以与之匹配。
3) MEX (元数据交换)的端点
<service name="wcfLib.StockService"
behaviorConfiguration="Metadata">
....
<endpoint name="mex"
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>有了所有这些,事情应该会很好!:-)
发布于 2012-11-01 02:02:43
我得到了完全相同的问题,并且正在积极地检查我的配置,所有的东西都与元数据端点一致,等等。这一行:
<service behaviorConfiguration="wcfLib.Service1Behavior" name="wcfLib.Service1">name值必须、必须具有实现协定的物理类的名称。我忘了..。一次又一次地随意命名它,认为它可以是任何字符串。因此,在上面的情况下,实现类必须命名为Service1。如果类名发生更改,请确保更改此值。
这就像是WCF 101的东西,尽管我从Framework3.0中的CTP开始就一直在做WCF,但我还是被它灼伤了。诸如此类。
发布于 2017-06-24 10:21:52
我打开了HTTP激活。一定要把它戴上。

https://stackoverflow.com/questions/5221692
复制相似问题