简体   繁体   中英

WCF Service runs perfectly when running under iis express but same service wont work when running under Local IIS with its virtual directory

I was practising WCF and stuck to this situation. My Wcf service works perfectly under IISExpress (default for VS2013). But When I use the same under Local IIS, I got below exception in WCF Test Client.

Error: Cannot obtain Metadata from http://localhost/WcfService1/Service1.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost/WcfService1/Service1.svc Metadata contains a reference that cannot be resolved: ' http://localhost/WcfService1/Service1.svc '. The remote server returned an unexpected response: (405) Method Not Allowed. The remote server returned an error: (405) Method Not Allowed.HTTP GET Error URI: http://localhost/WcfService1/Service1.svc There was an error downloading ' http://localhost/WcfService1/Service1.svc '. The request failed with HTTP status 404: Not Found.

My web config has endpoint for metadata exchange and also behaviour has httpGetEnabled true.

See web.config:

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

  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel.MessageLogging" switchValue="Warning,ActivityTracing">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelMessageLoggingListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="f:\tfs\wcfservice1\wcfservice1\web_messages.svclog"
        type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
        name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
        <filter type="" />
      </add>
    </sharedListeners>
    <trace autoflush="true" />
  </system.diagnostics>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <diagnostics>
      <messageLogging logEntireMessage="true" logMalformedMessages="true"
        logMessagesAtTransportLevel="true" />
    </diagnostics>
    <services>
      <service behaviorConfiguration="behave" name="WcfService1.Service1">
        <endpoint address="WcfService1.Service1" binding="basicHttpBinding" name="basicHttp"
          contract="WcfService1.IService1" />
        <endpoint binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost/WcfService1/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="behave">
          <serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </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>

I checked other WCF questions. but couldn't find answer. Thanks in advance.

When I use Local IIS, I am able to hit url http://localhost/wcfservice1/ and it shows me all files at that directory. but when I click on Service1.svc, it shows IIS error page.

HTTP Error 404.3 - Not Found The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

After addng WCF activation in IIS. Now I am getting different Error. I couldn't understand it. 在此处输入图片说明

You need to enable WCF in IIS Manager for your site, see: https://blogs.msdn.microsoft.com/blambert/2009/02/13/how-to-enable-iis7asp-net-and-wcf-http-activation/

Once WCF is enabled for IIS you should be able to run everything without a problem.

I resolved issue. I have turned on .Net framework 4.6 advanced services > WCF services > HTTP activation. Now WCF service is working perfectly.

Thanx to gmiley.. your previous answer led me there.

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