c# – WCF REST服务在本地工作正常,在远程服务器上发出Unauthorized(401)错误,而该服务具有匿名访问权限

我通过网络漫步但是找到了解决办法.

现在,WCF服务在本地完美运行,而在远程服务器上,它会为POST调用抛出401(未授权)Web异常. GET工作正常.

Implementation Details :
On the Remote Server-
    IIS : 6.0
    .NET : 4.0
    Calling App : WPF app.

On the Local Server-
    IIS : 7.0
    .NET : 4.0
    Calling App : WPF app.

该服务具有为web.config中的WCF rest指定的匿名访问权限.
对于身份验证我们已经实现了一个AuthManager类,它使用硬编码的用户名和密码对请求进行身份验证.

呼叫呼叫者时会添加网络凭据.

我呼叫本地网络时的标题是:

Authorization: Basic dG9ueXXXXXXX

而在呼叫服务器时:

Authorization: Negotiate TlRMTVNTUAABAAAAl4IIXXXXXXX

这对我来说很可疑.

下面给出的是服务的Web.config:

    <?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <connectionStrings>
    <add name="SqlServerConnectionString" connectionString="Data Source=BHUVINT\SQL2008R2;Initial Catalog=CPNS;User ID=sa;Password=orion@123"/>
  </connectionStrings>
  <system.diagnostics>
    <trace>
      <listeners>
        <add name="myListener"
                     type="System.Diagnostics.EventLogTraceListener"
             initializeData="Application" />
      </listeners>
    </trace>
  </system.diagnostics>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <machineKey decryption="AES" decryptionKey="0CA3EFAF0F7A5E7A62681C0BF656EE0ECE31ACEE3E1023BA3FAD20EA5F199DE8" validation="SHA1" validationKey="3E4528C0FFE94A75DF02052B358BD9DE40800DD89DE62168764FF0DCE537184F0535D5D9AD66DEDC97DC1ABFF7FA540B4DFD82E5BB196B95D15FF81F75AD5328" />
  </system.web>

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Mg">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="Mg" name="ApmWcfServiceWebRole.Push">
        <endpoint binding="webHttpBinding" name="firstBinding" contract="ApmWcfServiceWebRole.IPushService" />
      </service>
      <service behaviorConfiguration="Mg" name="ApmWcfServiceWebRole.WP7Device">
        <endpoint binding="webHttpBinding" name="secondBinding" contract="ApmWcfServiceWebRole.IWP7Service" />
      </service>
      <service behaviorConfiguration="Mg" name="ApmWcfServiceWebRole.iOSDevice">
        <endpoint binding="webHttpBinding" name="thirdBinding" contract="ApmWcfServiceWebRole.IIOSService" />
      </service>
      <service behaviorConfiguration="Mg" name="ApmWcfServiceWebRole.AndroidDevice">
        <endpoint binding="webHttpBinding" name="fourthBinding" contract="ApmWcfServiceWebRole.IAndroidService" />
      </service>
    </services>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">
    </serviceHostingEnvironment>

  </system.serviceModel>

  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
</configuration>

编辑:
仅调用AuthManager,其中正在进行POST,其中需要检查,并且这些是失败的.

编辑2:
我在AuthManager中添加了一个Trace,它没有收到凭证,它获得一个空值.似乎问题在于传递凭据.

提前致谢.

最佳答案 问题已得到解决:

我启用了匿名访问,但它在Windows身份验证上启用了检查,我删除了它并开始工作

我需要帮助解释它发生的原因,以便在请求到达我的跟踪时删除凭据.

点赞