【问题标题】:What is wrong with my WCF Meta Data Configuration?我的 WCF 元数据配置有什么问题?
【发布时间】:2012-05-07 01:30:06
【问题描述】:

这是this question 的后续内容,我已经配置了在 IIS 中运行的 WCF 服务(从 Visual Studio 2010 中)运行一个 Web 服务和一个 net.tcp 服务。经过大量黑客攻击后,我设法让 Web 服务加载到 WCF 测试客户端,但我无法让 Net.Tcp 服务加载到测试客户端。

这是我的 Web.config:

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

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="ServerService" behaviorConfiguration="ServerServiceBehaviour">
        <endpoint address="ServerService.svc" 
                  binding="netTcpBinding" 
                  bindingConfiguration="DefaultNetTcpBindingConfig" 
                  name="NetTcpEndPoint" 
                  contract="IServerService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>

        <endpoint address="mex"
                  binding="mexTcpBinding"
                  contract="IMetadataExchange" 
                  bindingConfiguration="mexTcpBinding"/>
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8523/"/>
          </baseAddresses>
        </host>
      </service>

      <service name="MyWebService" behaviorConfiguration="WebServiceBehaviour">
        <endpoint address="MyWebService.svc"
                  binding="wsHttpBinding"
                  bindingConfiguration="DefaultWSBinding"
                  name="MyWSEndPoint"
                  contract="IMyWebService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange"
                  bindingConfiguration="mexHttpBinding"/>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8523/"/>
          </baseAddresses>
        </host>
      </service>

    </services>
    <bindings>
      <netTcpBinding>
        <binding name="DefaultNetTcpBindingConfig"
                 maxConnections="5"
                 portSharingEnabled="true" >
        </binding>
        <!--<binding name="mexBinding"
                 portSharingEnabled="true">
          <security mode="None"></security>
        </binding>-->
      </netTcpBinding>
      <wsHttpBinding>
        <binding name="DefaultWSBinding"/>
      </wsHttpBinding>
      <mexTcpBinding>
        <binding name="mexTcpBinding"/>
      </mexTcpBinding>
      <mexHttpBinding>
        <binding name="mexHttpBinding"/>
      </mexHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServerServiceBehaviour">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above 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>
        <behavior name="MexBehaviour">
          <serviceMetadata httpGetEnabled="true" policyVersion="Policy15"/>
        </behavior>
        <behavior name="WebServiceBehaviour">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above 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>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>

当我运行 Visual Studio 调试器来发布服务时,我可以通过在 WCF 测试应用程序中输入以下 url 来访问 Web 服务:

http://localhost:8523/MyWebService.svc

但是,如果我在 WCF 测试应用程序中输入以下 URL,则会收到错误消息:

net.tcp://localhost:8523/ServerService.svc

这是我看到的错误:

错误:无法从 net.tcp://localhost:8523/ServerService.svc 如果这是 Windows (R) 请访问您有权访问的通信基础服务 检查您是否已在指定位置启用元数据发布 地址。有关启用元数据发布的帮助,请参阅 MSDN 文档位于 http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata交流 错误 URI:net.tcp://localhost:8523/ServerService.svc 元数据 包含无法解析的引用: 'net.tcp://localhost:8523/ServerService.svc'。你已经尝试过 为不支持 .Net 框架的服务创建通道。它 您可能会遇到 HTTP 端点。预期的 记录类型“PreambleAck”,找到“72”。

阅读this question 是否有可能VS 2010 中的网络服务器不支持net.tcp 绑定?

【问题讨论】:

  • 我认为问题可能是 Visual Studio 2010 中内置的 Web 服务器不支持 Net.Tct 绑定我正在安装 IIS,我将告诉它使用它。

标签: wcf web-config nettcpbinding


【解决方案1】:

看起来我看到的问题是 Visual Studio 2010 中的 Web 服务器不支持 Net.Tcp 绑定。

通过安装 IIS7(IIS6 也不支持 Net.Tcp)并告诉 Visual Studio 改用 IIS,我稍微更进一步了。

您可以通过转到服务的属性页面并选择“Web 选项卡”选择使用本地 IIS Web 服务器单选按钮并配置网络服务器来执行此操作。

您还可以在此选项卡上启动一个外部程序,使其启动 WcfTestClient.exe 并将 URL 作为命令行参数传递给您的服务。

我仍然有问题,但它们是不同的问题,所以我会提出另一个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-08
    • 2014-01-13
    • 2014-04-11
    • 2011-09-11
    • 2013-07-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多