繁体   English   中英

如何在IIS上托管WCF

[英]How to host my WCF on IIS

我在搜索中看到过类似的问题,但仍然无法解决。 我可以在本地主机上运行WCF并以简单的html调用方法,因此我知道它可以工作。

这是webconfig:

<?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”端点tbh。

当我尝试将其托管在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:     <!--

我从这里得到了答案: 配置错误:无法在此路径上使用此配置部分,未检查所有内容,因此我检查了除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

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

我以为我可能必须像WcFService Library一样开始一个新项目,但我无法使其正常工作。 相反,我只是删除了Service1.svc(带有一个代码隐藏文件),创建了一个新的Service1.cs文件,并将文本从过去的Service1.svc复制到了其中。 创建了一个新的Service1.svc,内容为:<%@ ServiceHost Service =“ WCFBolig.Service1”%>

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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