【问题标题】:WCF Service is not connecting to test clientWCF 服务未连接到测试客户端
【发布时间】:2019-10-27 05:37:19
【问题描述】:

我在运行测试客户端时不断收到此错误

添加服务失败。服务元数据可能无法访问。确保您的服务正在运行并公开元数据。

无法从http://localhost:50507/Service1.svc 获取元数据如果这是您有权访问的 Windows (R) Communication Foundation 服务,请检查您是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅位于 http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange 错误 URI:http://localhost:50507/Service1.svc 元数据包含无法解析的引用的 MSDN 文档:“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 指令中的服务属性值提供,或在配置元素 system.serviceModel/serviceHostingEnvironment/serviceActivations 中提供。找不到。

我已经在 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 的新手,但没有看到这一点。我已经搜索了互联网并公开了元数据文章以应用修复,但迄今为止没有任何效果

【问题讨论】:

  • 您是否尝试过指定一个特定端口,例如在许多 msdn 文档中看到的 8000 以供您的服务监听? localhost:8000/Service1.svc" binding="basicHttpBinding" contract="AgeCalculator.IService1"/>
  • 1) 您使用的是哪个版本的 .net? (4.6.2, 4.7, core?) 2) 您能否检查一下您的项目的/bin/debug/ 文件夹,以确认它在那里并且包含AgeCalculator.dll 之类的文件。
  • 您的服务名称是否正确 - “AgeCalculator.CalculateAge”?在其 Service1 下方

标签: c# wcf


【解决方案1】:

由于您似乎没有使用默认端口,因此最好在 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>

【讨论】:

  • 这很有帮助!谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-05
  • 1970-01-01
  • 2013-02-22
  • 2023-03-09
相关资源
最近更新 更多