运行测试客户端时,我总是收到此错误
添加服务失败。服务元数据可能无法访问。确保您的服务正在运行并公开元数据。
无法从http://localhost:50507/Service1.svc获取元数据。如果这是您有权访问的Windows(R)Communication Foundation服务,请检查是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅MSDN文档,位于http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange错误URI:http://localhost:50507/Service1.svc元数据包含无法解析的引用:'http://localhost:50507/Service1.svc'。无法激活请求的服务“ http://localhost:50507/Service1.svc”。有关更多信息,请参见服务器的诊断跟踪日志。HTTP GET错误URI:http://localhost:50507/Service1.svc下载'http://localhost:50507/Service1.svc'时出错。请求失败,并显示以下错误消息:-类型'AgeCalculator.Service1',作为ServiceHost指令中的Service属性值提供,或在配置元素system.serviceModel中提供。
我已经在web.config文件中使用以下代码公开了服务的元数据
<system.serviceModel>
<services>
<service name="AgeCalculator.CalculateAge" behaviorConfiguration="MetadataBehavior">
<endpoint address=""
binding="basicHttpBinding" contract="AgeCalculator.IService1">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="http://localhost/Service1.svc" binding="basicHttpBinding" contract="AgeCalculator.IService1"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MetadataBehavior">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
我查看了所有当前文档,但不知道问题出在哪里。可能是一个命名约定,因为我是WCF的新手,但没有看到这一点。我搜寻了互联网,并暴露了元数据文章以应用修复程序,但迄今为止没有任何进展
答案 0 :(得分:0)
由于您似乎没有使用默认端口,因此最好在service
绑定中指定端口。像这样更改您的service
定义:
<services>
<service name="AgeCalculator.CalculateAge" behaviorConfiguration="MetadataBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:50507/" />
</baseAddresses>
</host>
<endpoint address=""
binding="basicHttpBinding" contract="AgeCalculator.IService1" />
<endpoint address="mex"
binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="http://localhost:50507/Service1.svc"
binding="basicHttpBinding" contract="AgeCalculator.IService1"/>
</service>
</services>