【问题标题】:Issue when using WCF service in mvc在 mvc 中使用 WCF 服务时出现问题
【发布时间】:2016-12-28 14:20:46
【问题描述】:

我有一个带有 CSLA 的 WCF 项目,我已经在我的 IIS 服务器中发布了这个服务和 MVC 应用程序,但是从 Web 应用程序调用服务时它抛出了一个错误

System.ServiceModel.Security.SecurityNegotiationException:调用者未经服务验证。 ---> System.ServiceModel.FaultException: 由于身份验证失败,无法满足对安全令牌的请求。

这是我的服务 web.config

<system.serviceModel>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <services>
      <service name="Csla.Server.Hosts.WcfPortal" behaviorConfiguration="returnFaults">
        <endpoint binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_IWcfPortal" contract="Csla.Server.Hosts.IWcfPortal" />
      </service>
      <service name="Csla.Server.Hosts.Mobile.WcfPortal" behaviorConfiguration="returnFaults">
        <endpoint binding="basicHttpBinding" bindingConfiguration="basicHttpBinding_IWcfPortal" contract="Csla.Server.Hosts.Mobile.IWcfPortal" />
      </service>
    </services>
    <bindings>
      <basicHttpBinding>
        <binding name="basicHttpBinding_IWcfPortal" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647">
          <readerQuotas maxBytesPerRead="2147483647" maxArrayLength="2147483647" maxStringContentLength="2147483647" maxNameTableCharCount="2147483647" maxDepth="2147483647" />
        </binding>
      </basicHttpBinding>
      <wsHttpBinding>
        <binding name="wsHttpBinding_IWcfPortal" maxReceivedMessageSize="2147483647">
          <readerQuotas maxBytesPerRead="2147483647" maxArrayLength="2147483647" maxStringContentLength="2147483647" maxNameTableCharCount="2147483647" maxDepth="2147483647" />
        </binding>
      </wsHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="returnFaults">
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

我已经像这样在我的 MVC web.config 中使用了这个服务。

<add key="CslaAuthentication" value="Csla" /> 
<add key="CslaDataPortalProxy" value="Csla.DataPortalClient.WcfProxy, Csla" /> 
<add key="CslaDataPortalUrl" value="http://www.someurl.net/WcfFullPortal.svc" />

然后在我直接从我的服务项目中调用服务后,它工作正常。

<add key="CslaDataPortalUrl" value="http://localhost:11170/WcfFullPortal.svc" />

还尝试使用已发布的 IP 地址,也可以正常工作

<add key="CslaDataPortalUrl" value="http://10.4.56.75/WcfFullPortal.svc" />

只有当我使用已发布的主机名 (http://www.someurl.net/WcfFullPortal.svc) 时才会出现问题。我已经通过正常工作的浏览器打开了这个 URL。

【问题讨论】:

    标签: asp.net-mvc wcf csla


    【解决方案1】:

    在 web.config &lt;system.serviceModel&gt; 部分的部分之后添加以下绑定配置。

        <bindings>
            <wsHttpBinding>
               <binding name="TheBindingConfig">
                   <security mode="None" />
              </binding>
            </wsHttpBinding>
        </bindings>
    

    【讨论】:

    • 感谢@Ray 的重播。但这对我不起作用。它显示相同的错误。
    • 当你找到解决方案时,可以分享给我吗?谢谢
    • 我已经解决了这个问题。请在上面找到。
    【解决方案2】:

    只需将 Csla.DataPortalClient.WcfProxy 更改为 Csla.DataPortalClient.HttpProxy&lt;add key="CslaDataPortalUrl" value="http://www.someurl.net/WcfFullPortal.svc" /&gt;&lt;add key="CslaDataPortalUrl" value="http://www.someurl.net/DataPortal/PostAsync" /&gt;

    而且还要加

    protected void Application_AuthenticateRequest(Object sender, EventArgs e)
            {
                HttpContext.Current.User = new Csla.Security.UnauthenticatedPrincipal();
            }
    

    在 Global.asax.cs 中

    【讨论】:

      猜你喜欢
      • 2011-02-26
      • 2013-05-02
      • 1970-01-01
      • 1970-01-01
      • 2011-02-26
      • 2011-04-20
      • 2010-12-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多