【发布时间】:2011-03-07 15:45:42
【问题描述】:
我刚刚学习 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>
【问题讨论】:
-
您需要向我们展示您的 config 文件!像元数据交换这样的东西在配置中定义
-
您尝试连接到哪个 URL 以获取元数据?您如何托管此服务 - IIS 或自托管??
-
Yoru 代码和配置不匹配 - 您的代码中的服务是
wcfLib.StockService但您的标记包含 name=wcfLib.Service1- 这些名称需要匹配!与端点上的contract="wcfLib.ser"属性相同 - 需要匹配命名空间+接口名称! (wcfLib.IfaceService) -
我遇到了同样的问题,这是一个与名称不匹配的问题