简体   繁体   中英

Can't add WCF service reference hosted on Azure VM to VS2015 project

I'm trying to add a service reference to my VS2015 project. The service is published on IIS in Windows Server 2012 hosted in an Azure VM. This is the 1st time I'm hosting a service inside an Azure VM (Windows Server 2012) so I don't know what I might have been doing wrong.

I can access the TheService.svc file in my web browser normally (ie: http://xxxxxx.xxxxx.cloudapp.azure.com/TheService/TheService.svc ).

But when I try to add the service reference using the same adress in my VS project, it just hangs to: Please wait for service information to be downloaded or click Stop and the metadata is never downloaded.

Here is the service configuration in the 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>

It looks like you have not published the metadata for the service, try:

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

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

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" xdt:Transform="SetAttributes(multipleSiteBindingsEnabled)"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM