WCF - 无法通过浏览器访问 MEX

WCF - can't access to MEX via browser

我刚刚用几乎默认的配置创建了新项目"WCF Service Library":

    <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    <add key="ClientSettingsProvider.ServiceUri" value="" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="WcfServiceLibrary1.Service1">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
            <!--<add baseAddress="net.tcp://localhost:8734/Design_Time_Addresses/WcfServiceLibrary1/Service1/" /> -->
          </baseAddresses>
        </host>
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="" contract="WcfServiceLibrary1.IService1">
          <identity><dns value="localhost" /></identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="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>
  </system.serviceModel>
</configuration>

它在 WcfSvcHost 中运行完美,但是当我尝试通过浏览器(Edge 或 Firefox)访问 http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/mex 时,我收到 HTTP 错误 400。

WCF 测试客户端使用该 URI 工作正常。

我尝试将 "name" 属性添加到行为标签,然后在服务标签中使用此名称 - 没有帮助。

令人惊讶的是,只有在注释以下字符串时我才能修复它:

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

当 WCF 测试客户端中的地址更改为:http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1?wsdl

并且此 URI 在浏览器中运行良好。但我认为这不是一个正确的方法。

我在 Windows 10 x64 机器上使用 Visual Studio 2015 and.Net Framework 4.5.2。

非常感谢任何帮助。

更新。明确一点:我想在浏览器中查看我的服务页面(以文本 "You have created a service" 开头)。当我删除 "mex" 端点时,我只能看到 .wsdl 文件 - 这不是我想要的。

刚刚找到答案 - 正确的 URI 是: http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/ (最后没有 "mex")。