2016-05-28 3 views
1

Я практиковал WCF и придерживался этой ситуации. Служба Wcf отлично работает под IISExpress (по умолчанию для VS2013). Но когда я использую то же самое в Local IIS, в WCF Test Client я получил меньше исключения.WCF Service отлично работает при работе под iis express, но тот же сервис не работает при работе в Local IIS с его виртуальным каталогом

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.

Мой веб-конфигурации имеет конечную точку для обмена метаданными, а также поведение httpGetEnabled верно.

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

Я проверил другие вопросы WCF. но не смог найти ответ. Спасибо заранее.

Когда я пользуюсь локальным IIS, я могу нанести урон http://localhost/wcfservice1/ и он показывает мне все файлы в этом каталоге. , но когда я нажимаю на Service1.svc, он показывает страницу ошибки IIS.

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.

После активации WCF в IIS. Теперь я получаю другую ошибку. Я не мог этого понять. enter image description here

+0

Если вы заходите на сайт в диспетчере IIS, можете ли вы щелкнуть правой кнопкой мыши и перейти к нему? Работает ли ваш сайт IIS и настроен на порт 80? – gmiley

+0

Я бы заглянул в привязки http vs https. Кажется, вы только открываете https, но метаданные могут быть доступны только для http. – faester

+0

Я обновил свой вопрос с необходимой информацией. – Sagar

ответ

3

Вам необходимо включить WCF в диспетчере IIS для вашего сайта, см: https://blogs.msdn.microsoft.com/blambert/2009/02/13/how-to-enable-iis7asp-net-and-wcf-http-activation/

После WCF включена для IIS, вы должны быть в состоянии выполнить все без проблем.

+0

Привет, у меня есть изменения, как вы предложили. и теперь я получаю еще одну ошибку. Я опубликовал фотографию в своем вопросе. – Sagar

+0

Вы переработали IIS, остановитесь, а затем снова запустите его, так как вы внесли изменения, а затем попробуйте получить доступ к сайту? – gmiley

+0

Да .. попробовал. Я получаю такую ​​же ошибку. Я приложил изображение в вопросе. – Sagar

1

Я разрешил выпуск. Я включил .Net framework 4.6 расширенные службы> службы WCF> HTTP-активация. Теперь служба WCF работает отлично.

Thanx to gmiley .. ваш предыдущий ответ привел меня туда.