Asp.net

WCF 服務問題 - 不支持協議“http”。如何解決?

  • August 30, 2019

我在我的開發盒上設置了 WCF 服務後,但在訪問它時出現錯誤。我已經按照本指南設置了服務。它是用VS2008 / C# / .NET 3.5編寫的,我的開發盒是帶有IIS 7的****Vista SP2。目前,該服務只不過是預設結構,因為我實際上是在測試與它的連接之後。

我已經檢查了需要安裝的內容,並且我很確定我已經啟用了所有功能,下面的螢幕截圖顯示了目前選項:

Windows IIS 選項

訪問**http://localhost:8000/Service.svc**的完整錯誤資訊如下:

Server Error in '/' Application.
--------------------------------------------------------------------------------

The protocol 'http' is not supported. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The protocol 'http' is not supported.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[InvalidOperationException: The protocol 'http' is not supported.]
  System.ServiceModel.AsyncResult.End(IAsyncResult result) +11536522
  System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +194
  System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +176
  System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +278
  System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +68
  System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4016; ASP.NET Version:2.0.50727.4016 

任何有關如何調試/修復錯誤的建議將不勝感激。Google搜尋錯誤幾乎沒有幫助。我可能錯過了一些非常明顯的東西!

編輯- web.config 根據要求(抱歉其長度):

<?xml version="1.0"?>
<!--
   Note: As an alternative to hand editing this file you can use the 
   web admin tool to configure settings for your application. Use
   the Website->Asp.Net Configuration option in Visual Studio.
   A full list of settings and comments can be found in 
   machine.config.comments usually located in 
   \Windows\Microsoft.Net\Framework\v2.x\Config 
-->
<configuration>
   <configSections>
       <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
           <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
               <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
               <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
                   <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
                   <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                   <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                   <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
               </sectionGroup>
           </sectionGroup>
       </sectionGroup>
   </configSections>
   <appSettings/>
   <connectionStrings/>
   <system.web>
       <!--
           Set compilation debug="true" to insert debugging 
           symbols into the compiled page. Because this 
           affects performance, set this value to true only 
           during development.
       -->
       <compilation debug="true">
           <assemblies>
               <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
               <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
               <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
               <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
           </assemblies>
       </compilation>
       <!--
           The <authentication> section enables configuration 
           of the security authentication mode used by 
           ASP.NET to identify an incoming user. 
       -->
       <authentication mode="Windows"/>
       <!--
           The <customErrors> section enables configuration 
           of what to do if/when an unhandled error occurs 
           during the execution of a request. Specifically, 
           it enables developers to configure html error pages 
           to be displayed in place of a error stack trace.

       <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
           <error statusCode="403" redirect="NoAccess.htm" />
           <error statusCode="404" redirect="FileNotFound.htm" />
       </customErrors>
       -->
       <pages>
           <controls>
               <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
           </controls>
       </pages>
       <httpHandlers>
           &lt;remove verb="*" path="*.asmx"/&gt;
           &lt;add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
           &lt;add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
           &lt;add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/&gt;
       &lt;/httpHandlers&gt;
       <httpModules>
           &lt;add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
       &lt;/httpModules&gt;
   &lt;/system.web&gt;
   &lt;system.codedom&gt;
       &lt;compilers&gt;
           &lt;compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt;
               &lt;providerOption name="CompilerVersion" value="v3.5"/&gt;
               &lt;providerOption name="WarnAsError" value="false"/&gt;
           &lt;/compiler&gt;
           &lt;compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt;
               &lt;providerOption name="CompilerVersion" value="v3.5"/&gt;
               &lt;providerOption name="OptionInfer" value="true"/&gt;
               &lt;providerOption name="WarnAsError" value="false"/&gt;
           &lt;/compiler&gt;
       &lt;/compilers&gt;
   &lt;/system.codedom&gt;
   &lt;system.web.extensions&gt;
       &lt;scripting&gt;
           &lt;webServices&gt;
               &lt;!--
             Uncomment this section to enable the authentication service. Include 
             requireSSL="true" if appropriate. 

         &lt;authenticationService enabled="true" requireSSL = "true|false"/&gt;
         --&gt;
               &lt;!--
             Uncomment these lines to enable the profile service, and to choose the 
             profile properties that can be retrieved and modified in ASP.NET AJAX 
             applications.

          &lt;profileService enabled="true"
                          readAccessProperties="propertyname1,propertyname2"
                          writeAccessProperties="propertyname1,propertyname2" /&gt;
         --&gt;
               &lt;!--
             Uncomment this section to enable the role service.

         &lt;roleService enabled="true"/&gt;
         --&gt;
           &lt;/webServices&gt;
           &lt;!--
       &lt;scriptResourceHandler enableCompression="true" enableCaching="true" /&gt;
       --&gt;
       &lt;/scripting&gt;
   &lt;/system.web.extensions&gt;
   &lt;!--
       The system.webServer section is required for running ASP.NET AJAX under Internet
       Information Services 7.0.  It is not necessary for previous version of IIS.
   --&gt;
   &lt;system.webServer&gt;
       &lt;validation validateIntegratedModeConfiguration="false"/&gt;
       &lt;modules&gt;
           &lt;add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
       &lt;/modules&gt;
       &lt;handlers&gt;
           &lt;remove name="WebServiceHandlerFactory-Integrated"/&gt;
           &lt;add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
           &lt;add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
           &lt;add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/&gt;
       &lt;/handlers&gt;
   &lt;/system.webServer&gt;
   &lt;system.serviceModel&gt;
       &lt;services&gt;
           &lt;service name="Service" behaviorConfiguration="ServiceBehavior"&gt;
               &lt;!-- Service Endpoints --&gt;
               &lt;endpoint address="" binding="wsHttpBinding" contract="IService"&gt;
                   &lt;!-- 
             Upon deployment, the following identity element should be removed or replaced to reflect the 
             identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
             automatically.
         --&gt;
                   &lt;identity&gt;
                       &lt;dns value="localhost"/&gt;
                   &lt;/identity&gt;
               &lt;/endpoint&gt;
               &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/&gt;
       &lt;host&gt;
         &lt;baseAddresses&gt;
           &lt;add baseAddress="http://localhost:8000/" /&gt;
         &lt;/baseAddresses&gt;
       &lt;/host&gt;
     &lt;/service&gt;
       &lt;/services&gt;
       &lt;behaviors&gt;
           &lt;serviceBehaviors&gt;
               &lt;behavior name="ServiceBehavior"&gt;
                   &lt;!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --&gt;
                   &lt;serviceMetadata httpGetEnabled="true"/&gt;
                   &lt;!-- 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 --&gt;
                   &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt;
               &lt;/behavior&gt;
           &lt;/serviceBehaviors&gt;
       &lt;/behaviors&gt;
   &lt;/system.serviceModel&gt;
&lt;/configuration&gt;

編輯 2 - 因為 Delphi 2007 不支持 WCF 服務使用的 SOAP 1.2,所以我刪除了有關創建 Delphi Win32 客戶端的段落。Delphi 2007 只支持 SOAP 1.0…所以客戶端現在將是一個 C# WinForms 應用程序。

對我來說,答案如下(由 Lazarus 在評論中提供,但沒有回來作為答案發布):

  1. 啟動Internet 資訊服務 (IIS) 管理器
  2. 打開站點文件夾選擇有問題的站點
  3. 右鍵點擊它,然後選擇管理網站,然後選擇高級設置…
  4. 在出現的彈出視窗中,我在Enabled Protocols行中輸入了http 。
  5. 關閉彈出視窗並重新啟動站點,就是這樣。固定的!

我發現 , 和/或 的配置方式幾乎總是endpointbindings問題behavior

在大多數情況下,如果您在 IIS 中的網站沒有 HTTP 綁定,那麼請確保在configuration/system.serviceModel/behaviors/serviceBehaviors/behavior/serviceMetadata配置中針對您的 WCF 服務顯式設置 httpGet httpGetEnabled=‘false’。上面的路徑當然是指您的 web 或 app.config 文件。

此外,如果您的端點地址中包含“http://”,請將其刪除。WCF 會注意這些事情,並且會拋出相同的模棱兩可的錯誤消息。有一大堆錯誤配置會產生相同的錯誤消息。(我討厭 WCF。)我更具體的是:“嘿,愚蠢的 as#!您的端點地址之一中有一個 HTTP,但 IIS 沒有 HTTP 綁定!” ;P 至少這樣我就不會追我的尾巴了。

同樣,我從不使用mex端點,因為它們比它們的價值更麻煩。相反,請使用 config 元素中的httpsHelpPageUrlandhttpsHelpPageEnabled屬性configuration/system.serviceModel/behaviors/serviceBehaviors/behavior/serviceDebug(假設您正在使用HTTPS)。

引用自:https://stackoverflow.com/questions/1165419