【问题标题】:How to host my WCF on IIS如何在 IIS 上托管我的 WCF
【发布时间】:2018-06-14 13:02:35
【问题描述】:

我在搜索中看到过这样的问题,但我仍然无法弄清楚。 我可以在本地主机上运行我的 WCF 并在一个简单的 html 中调用这些方法,所以我知道它可以工作。

这是网络配置:

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

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.6.1"/>
    <pages validateRequest="false" />
    <httpRuntime targetFramework="4.6.1"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors >
        <behavior name="ServiceBehavior">
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="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="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <services>
      <service name="WCFBolig.Service1" behaviorConfiguration="ServiceBehavior">
        <endpoint binding="webHttpBinding" 
                  contract="WCFBolig.IService1"
                  behaviorConfiguration="web"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <serviceHostingEnvironment  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>
  <connectionStrings>
    <add
      name="DatabaseConnection"
      connectionString="server=XX;database=XX;user=XX;password=XX"
      providerName="System.Data.SqlClient"
  />
  </connectionStrings>
</configuration>

我不确定是否需要“mex”端点。

当我尝试在 IIS 上托管它时,我右键单击站点,添加网站,为其命名和端口,但我不确定物理路径。我已经尝试使用直接指向项目的路径:C:\Users\me\source\repos\WCFBolig\WCFBolig

我在尝试浏览时收到此错误:

HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.

Detailed Error Information:
Module     IIS Web Core
Notification       Unknown
Handler    Not yet determined
Error Code     0x80070005
Config Error       Cannot read configuration file due to insufficient permissions
Config File    \\?\C:\Users\me\source\repos\WCFBolig\WCFBolig\web.config
Requested URL      http://localhost:777/
Physical Path      
Logon Method       Not yet determined
Logon User     Not yet determined

Config Source:
   -1: 
    0: 

我尝试将文件夹移动到其他地方,看看它是否可以在那里访问它,但没有奏效。我试过查看 webconfig 文件的权限,但看不到与 IIS 有任何关系。

正确的步骤是什么? 如果我需要发布有关该项目的更多信息,请告诉我,无论如何感谢您的宝贵时间。

编辑:新错误万岁:

HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.

Detailed Error Information:
Module     IIS Web Core
Notification       BeginRequest
Handler    Not yet determined
Error Code     0x80070021
Config Error       This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
Config File    \\?\C:\inetpub\WCFBolig\WCFBolig\web.config
Requested URL      http://localhost:7778/Service1.svc
Physical Path      C:\inetpub\WCFBolig\WCFBolig\Service1.svc
Logon Method       Not yet determined
Logon User     Not yet determined

Config Source:
   38:   <system.webServer>
   39:     <modules runAllManagedModulesForAllRequests="true"/>
   40:     <!--

我从这里得到了答案:Config Error: This configuration section cannot be used at this path 他们都没有被检查,所以我检查了除了 CGI 之外的所有内容,现在得到这个错误:

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.

Most likely causes:
It is possible that a handler mapping is missing. By default, the static file handler processes all content.
The feature you are trying to use may not be installed.
The appropriate MIME map is not enabled for the Web site or application. (Warning: Do not create a MIME map for content that users should not download, such as .ASPX pages or .config files.)
If ASP.NET is not installed.

Things you can try:
In system.webServer/handlers:
Ensure that the expected handler for the current page is mapped.
Pay extra attention to preconditions (for example, runtimeVersion, pipelineMode, bitness) and compare them to the settings for your application pool.
Pay extra attention to typographical errors in the expected handler line.
Please verify that the feature you are trying to use is installed.
Verify that the MIME map is enabled or add the MIME map for the Web site using the command-line tool appcmd.exe.
To set a MIME type, use the following syntax: %SystemRoot%\windows\system32\inetsrv\appcmd set config /section:staticContent /+[fileExtension='string',mimeType='string']
The variable fileExtension string is the file name extension and the variable mimeType string is the file type description.
For example, to add a MIME map for a file which has the extension ".xyz": appcmd set config /section:staticContent /+[fileExtension='.xyz',mimeType='text/plain']
Warning: Ensure that this MIME mapping is needed for your Web server before adding it to the list. Configuration files such as .CONFIG or dynamic scripting pages such as .ASP or .ASPX, should not be downloaded directly and should always be processed through a handler. Other files such as database files or those used to store configuration, like .XML or .MDF, are sometimes used to store configuration information. Determine if clients can download these file types before enabling them.
Install ASP.NET.
Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click here.

Detailed Error Information:
Module     StaticFileModule
Notification       ExecuteRequestHandler
Handler    StaticFile
Error Code     0x80070032
Requested URL      http://localhost:7778/Service1.svc
Physical Path      C:\inetpub\WCFBolig\WCFBolig\Service1.svc
Logon Method       Anonymous
Logon User     Anonymous

【问题讨论】:

  • 嗯,它一个权限问题,IIS用户不能访问你的个人目录,所以你必须把服务放在一个可以访问的目录。如果这导致一个新的错误,那么研究那个错误。
  • 哦,我已将其移至默认网站的文件所在的位置,您是对的,我确实收到了一条新的错误消息。谢谢,我会做更多的研究。
  • 您是否在 Windows Features .NET Framework 中为 HTTP 激活了 WCF?
  • 你写的 当我尝试在 IIS 上托管它时,我右键单击站点,添加网站,给它一个名称和一个端口这是错误的,你需要创建Application 不是 website

标签: c# wcf iis


【解决方案1】:

所以我已经弄清楚了,这几乎是我在其他 stackoverflow 线程上读到的内容,我只需要正确地遵循它们。

我想我可能需要启动一个新项目作为 WcFService 库,但我无法让它工作。相反,我只是删除了 Service1.svc(带有代码隐藏文件),创建了一个新的 Service1.cs 文件并将过去 Service1.svc 中的文本复制到其中。创建了一个新的 Service1.svc 并以此为内容:

我还必须将其添加为应用程序,而不是像我尝试那样添加为新网站。

【讨论】:

    猜你喜欢
    • 2016-06-06
    • 2013-10-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-06
    • 1970-01-01
    • 1970-01-01
    • 2015-05-05
    相关资源
    最近更新 更多