【问题标题】:Can't add WCF service reference hosted on Azure VM to VS2015 project无法将 Azure VM 上托管的 WCF 服务引用添加到 VS2015 项目
【发布时间】:2018-03-17 03:53:11
【问题描述】:

我正在尝试向我的 VS2015 项目添加服务引用。该服务在 Azure VM 中托管的 Windows Server 2012 中的 IIS 上发布。这是我第一次在 Azure VM (Windows Server 2012) 中托管服务,所以我不知道我可能做错了什么。

我可以在我的网络浏览器中正常访问 TheService.svc 文件(即:http://xxxxxx.xxxxx.cloudapp.azure.com/TheService/TheService.svc)。

但是当我尝试在我的 VS 项目中使用相同的地址添加服务引用时,它只是挂在:Please wait for service information to be downloaded or click Stop 并且永远不会下载元数据。

这里是web.config中的服务配置:

<system.serviceModel>
    <diagnostics>
      <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
    </diagnostics>
    <bindings>
      <basicHttpBinding>
        <binding name="TestBinding" closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="true" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed" messageEncoding="Text">
          <readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="TheService.TheService">
        <endpoint address="http://localhost/TheService/TheService.svc" binding="basicHttpBinding" bindingConfiguration="TestBinding" name="TheService_Local" contract="TheService.ITheService" />
        <host>
          <timeouts openTimeout="00:10:00" />
        </host>
      </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="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  </system.serviceModel>

【问题讨论】:

  • 尝试在WcfTestClient.exe应用程序中添加引用。 docs.microsoft.com/en-us/dotnet/framework/wcf/…
  • 此外,您可以使用svcutil.exe 生成服务模型代码。 docs.microsoft.com/en-us/dotnet/framework/wcf/…
  • 试过WcfTestClient,进度条完成50%后,新窗口打开但卡住了,但我可以在后面的状态栏中看到:Failed to add service. Service metadata may not be accessible. Make sure your service is running and exposing metadata
  • 所以元数据没有被提供者暴露,你仍然可以使用svcutil.exe来生成服务模型。并将生成的文件和配置添加到您的应用程序中。
  • 我已更新我的帖子以包含更多 web.config 部分。我会尝试 svcutil

标签: c# web-services wcf azure visual-studio-2015


【解决方案1】:

您似乎还没有发布服务的元数据,请尝试:

 <service name="TheService.TheService">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="TestBinding" name="TheService_Local" contract="TheService.ITheService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <timeouts openTimeout="00:10:00" />
    </host>
  </service>

【讨论】:

    【解决方案2】:

    我通过在 web.config 转换文件中设置此属性解决了我的问题:

    &lt;serviceHostingEnvironment multipleSiteBindingsEnabled="true" xdt:Transform="SetAttributes(multipleSiteBindingsEnabled)"/&gt;

    【讨论】:

      猜你喜欢
      • 2011-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-17
      相关资源
      最近更新 更多