简体   繁体   English

WCF服务未连接到测试客户端

[英]WCF Service is not connecting to test client

I keep getting this error when I run the test client 我运行测试客户端时不断收到此错误

Failed to add a service. 无法添加服务。 Service metadata may not be accessible. 可能无法访问服务元数据。 Make sure your service is running and exposing metadata. 确保您的服务正在运行并公开元数据。

Cannot obtain Metadata from http://localhost:50507/Service1.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. 无法从http:// localhost:50507 / Service1.svc获取元数据如果这是您有权访问的Windows(R)Communication Foundation服务,请检查您是否已在指定地址启用元数据发布。 For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:50507/Service1.svc Metadata contains a reference that cannot be resolved: ' http://localhost:50507/Service1.svc '. 有关启用元数据发布的帮助,请参阅http://go.microsoft.com/fwlink/?LinkId=65455上的MSDN文档.WS- Metadata Exchange错误URI: http:// localhost:50507 / Service1.svc元数据包含无法解析的引用:' http:// localhost:50507 / Service1.svc '。 The requested service, ' http://localhost:50507/Service1.svc ' could not be activated. 无法激活所请求的服务“ http:// localhost:50507 / Service1.svc ”。 See the server's diagnostic trace logs for more information.HTTP GET Error URI: http://localhost:50507/Service1.svc There was an error downloading ' http://localhost:50507/Service1.svc '. 有关详细信息,请参阅服务器的诊断跟踪日志.HTTP GET错误URI: http:// localhost:50507 / Service1.svc下载' http:// localhost:50507 / Service1.svc '时出错 The request failed with the error message:-- The type 'AgeCalculator.Service1', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found. 请求失败并显示错误消息: - 类型'AgeCalculator.Service1',作为ServiceHost指令中的Service属性值提供,或者在配置元素system.serviceModel / serviceHostingEnvironment / serviceActivations中提供。

I have already exposed the metadata of the service with the following code in the web.config file 我已经使用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" />

I have looked at all current documentation and don't know what the issue is. 我查看了所有当前的文档,但不知道问题是什么。 May be a naming convention as I am brand new to WCF but not seeing this. 可能是一个命名约定,因为我是WCF的新手,但没有看到这个。 I have scoured the internet and exposing the metadata articles to apply fixes and nothing has worked to date 我已经浏览了互联网并公开了元数据文章以应用修复程序,迄今为止没有任何工作

Since you don't seem to be using the default port, it is best to specify the port in your service binding. 由于您似乎没有使用默认端口,因此最好在service绑定中指定端口。 Change your service definition like this: 像这样更改您的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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM