wcf net.tcp绑定抛出错误无法识别URI前缀,http绑定有效

时间:2014-06-25 23:13:46

标签: wcf net.tcp

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

此时我已经花了一整天的时间试图找出原因,并且已经完成了有关堆栈溢出主题的大部分帖子。在这一点上,我觉得我遗漏了一些基本的东西,并且非常感谢专家的任何反馈。

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

我采取的步骤

  1. 在localhost上设置一个新网站,启用net.tcp(不含空格)enter image description here
  2. 确保net.tcp的所有三项服务都在运行enter image description here
  3. 在webconfig中禁用安全性(无代替Windows)enter image description here
  4. 我的服务详情

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

    web config

    <?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.
    

1 个答案:

答案 0 :(得分:0)

您是通过参考文献添加参考文献 - &gt;服务参考?我使用了您的Web配置文件,并且能够成功运行并使用控制台应用程序的WCF服务。

相关问题