1

我们已经为我们的 Intranet 开发了一组带有 lightswitch 的应用程序。它们都使用 Windows 身份验证运行,但现在我们必须开发一些必须允许匿名连接的 wcf 服务(托管在 LS 应用程序中)。

这是我公开服务的当前 web.config 设置:

<system.web>
  <authentication mode="Windows">
      <forms name="Main" />
  </authentication>
  <identity impersonate="true" />
</system.web>

<system.serviceModel>
   <services>
      <service behaviorConfiguration="metadataSupport" name="LightSwitchApplication.WCF.HelperService">
        <endpoint address="" binding="customBinding" bindingConfiguration="LightSwitchApplication.WCF.HelperService.customBinding0" contract="LightSwitchApplication.WCF.HelperService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
   </services>
   <bindings>
      <customBinding>
        <binding name="LightSwitchApplication.WCF.HelperService.customBinding0">
          <binaryMessageEncoding />
          <httpTransport authenticationScheme="Anonymous" />
        </binding>
      </customBinding>
    </bindings>
</system.serviceModel>

在这里挖掘并进入 msdn 之后,我仍然没有找到是否有办法达到这种行为。

当我使用 Windows 凭据访问这些服务时,一切正常,我发现无法通过匿名身份验证使用这些服务。我尝试更改绑定模式,将此装饰添加到我的服务中:

[ServiceContract(Namespace="")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[AllowAnonymous]
[SecurityPermission(SecurityAction.Assert)]
[OverrideAuthentication()]
[Authorize(Users="*")]
[OverrideAuthorization()]
public class HelperService
{
  ...
}

我也尝试在我的 web.config 中使用标签,并将我的 WCF 文件夹设置为主文件夹下的应用程序,但在这种情况下,问题是不同的,并且与编译路径和 dll 目录路径有关。我试图解决它:

<location path="WCF">
<system.web>
        <authentication mode="None" />
        <compilation>
            <codeSubDirectories>
                <add directoryName="../bin"/>
            </codeSubDirectories>
        </compilation>
</location>

但我仍然收到错误,因为 IIS 仍然找不到我的程序集:无法加载文件或程序集 'Microsoft.LightSwitch.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 或其依赖项之一。该系统找不到指定的文件。

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.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.LightSwitch.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

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.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'Microsoft.LightSwitch.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' could not be loaded.


=== Pre-bind state information ===
LOG: User = IIS APPPOOL\DefaultAppPool
LOG: DisplayName = Microsoft.LightSwitch.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///C:/inetpub/wwwroot/MyApp/WCF/
LOG: Initial PrivatePath = C:\inetpub\wwwroot\MyApp\WCF\bin
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\inetpub\wwwroot\MyApp\WCF\web.config
LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.LightSwitch.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/MyApp_wcf/88e6cc1b/e1821fec/Microsoft.LightSwitch.Server.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/MyApp_wcf/88e6cc1b/e1821fec/Microsoft.LightSwitch.Server/Microsoft.LightSwitch.Server.DLL.
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/MyApp/WCF/bin/Microsoft.LightSwitch.Server.DLL.
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/MyApp/WCF/bin/Microsoft.LightSwitch.Server/Microsoft.LightSwitch.Server.DLL.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/MyApp_wcf/88e6cc1b/e1821fec/Microsoft.LightSwitch.Server.EXE.
LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/Temporary ASP.NET Files/MyApp_wcf/88e6cc1b/e1821fec/Microsoft.LightSwitch.Server/Microsoft.LightSwitch.Server.EXE.
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/MyApp/WCF/bin/Microsoft.LightSwitch.Server.EXE.
LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/MyApp/WCF/bin/Microsoft.LightSwitch.Server/Microsoft.LightSwitch.Server.EXE.

好的,不管这个...我将整个 bin 文件夹从父文件夹复制到 MyApp/wcf (只是为了测试,我稍后会解决它)最后加载应用程序,但是...现在我得到一个 401.2错误:

Error message 401.2.: Unauthorized: Logon failed due to server configuration.  Verify that you have permission to view this directory or page based on the credentials you supplied and the authentication methods enabled on the Web server.  Contact the Web server's administrator for additional assistance.

我还在 WCF 文件夹中创建了一个 web.config,允许以这种方式匿名访问:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <security>
            <authentication>
                <anonymousAuthentication enabled="true" />
                <windowsAuthentication enabled="false" />
            </authentication>
            <authorization>
                <add accessType="Allow" users="?" />
            </authorization>
        </security>
    </system.webServer>
    <system.web>
        <identity impersonate="false" />
    </system.web>
</configuration>

我需要帮助来解决它,因为它让我发疯。我想重用我们 LightSwitch 应用程序中定义的所有业务逻辑,但我仍然不知道我是否能够处理这样一个“愚蠢的事情”

你能告诉我正确的方法吗?

非常感谢。

4

0 回答 0