如何在IIS上托管我的WCF

时间:2018-06-14 13:02:36

标签: c# wcf iis

我在搜索中看到过这样的问题,但我仍然无法弄明白。 我可以在localhost上运行我的WCF并在一个简单的html中调用方法,所以我知道它的工作原理。

这是webconfig:

sage -n sagenb

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

当我尝试在IIS上托管它时,我右键单击“站点”,添加网站,给它命名和端口,但我不确定物理路径。我已尝试直接进入项目路径:C:\ Users \ me \ source \ repos \ WCFBolig \ WCFBolig

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

<?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>

我已经尝试将文件夹移动到其他地方以查看它是否可以在那里访问它但是没有用。我已经尝试查看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       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: 

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

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:     <!--

1 个答案:

答案 0 :(得分:0)

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

我想我可能不得不开始一个新的项目作为WcFService Library,但我无法让它工作。相反,我只删除了Service1.svc(带有codebehind-file),创建了一个新的Service1.cs文件,并将过去的Service1.svc中的文本复制到其中。创建了一个新的Service1.svc,并将其作为内容:&lt;%@ ServiceHost Service =“WCFBolig.Service1”%&gt;

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

相关问题