【问题标题】:wcf net.tcp binding throwing error The URI prefix is not recognized, http binding workswcf net.tcp 绑定抛出错误 URI 前缀无法识别,http 绑定有效
【发布时间】:2014-06-25 23:13:46
【问题描述】:

我在运行 windows7 的本地计算机上的 IIS 7 中托管了一个简单的 wcf 服务,我尝试使用 winform 访问它,但无论我尝试什么,都会出现相同的错误。我可以通过 http 访问该服务。

在这一点上,我花了一整天的时间试图找出原因,并浏览了关于堆栈溢出主题的大部分帖子。在这一点上,我觉得我缺少一些基本的东西,我们非常感谢专家的任何反馈。

即使你指导我如何调试这个或在哪里寻找确切的原因,这将有很大帮助,因为我在事件日志或失败的请求跟踪中看不到任何有用的东西:(

我已经采取的步骤

  1. 在 localhost 上设置一个新网站,启用 net.tcp(不带空格)!
  2. 确保 net.tcp 的所有三个服务都在运行
  3. 在 webconfig 中禁用安全性(无而不是 windows)。

我的服务详情

namespace WcfService1
{
   public class Service1 : IService1
    {
        public string Echo(string msg)
        {
            return DateTime.Now.ToString();
        }
    }
}

网络配置

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="WcfService1.Service1">
        <endpoint address="" binding="netTcpBinding" bindingConfiguration="tcpBinding" contract="WcfService1.IService1" >
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:820/Service1.svc"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <bindings>
      <netTcpBinding>
        <binding name="tcpBinding" portSharingEnabled="true">
          <security mode="None"></security>
        </binding>
      </netTcpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <!--<protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>-->    

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

完整的错误详情

The URI prefix is not recognized.
Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:820/Service1.svc'.
The requested service, 'net.tcp://localhost:820/Service1.svc' could not be activated. See the server's diagnostic trace logs for more information.
If the service is defined in the current solution, try building the solution and adding the service reference again.

【问题讨论】:

  • 相当怀疑是不是这样,但您可以尝试取消注释&lt;protocolMapping&gt; 部分并添加&lt;add binding="netTcpBinding" scheme="net.tcp" /&gt;。还要查看 IIS 日志和事件查看器,看看那里是否有任何信息。
  • 感谢蒂姆的建议,我已经尝试过了,但我要查看 iis 日志,看看是否有任何发现。

标签: wcf net.tcp


【解决方案1】:

您是通过 References --> Service Reference 添加引用吗?我使用了您的 Web 配置文件,并且能够成功地为控制台应用程序运行和使用 WCF 服务。

【讨论】:

  • 您好 Aditya,我将其添加为服务参考。让我问你这个问题,你是在 IIS 中本地托管服务还是将其作为解决方案的一部分?
  • 您有作为库或应用程序的服务吗?我将服务作为 wcf 服务应用程序而不是库
  • 我将它作为一个应用程序,并在 IIS 中本地托管它。
猜你喜欢
  • 2013-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-05
  • 2020-03-23
  • 1970-01-01
  • 1970-01-01
  • 2014-04-29
相关资源
最近更新 更多