asp.net-mvcwcfcsla

Issue when using WCF service in mvc


I have a WCF project with CSLA and I have published this service and MVC application in my IIS Server, but it's throwing one error when calling the service from Web app

System.ServiceModel.Security.SecurityNegotiationException: The caller was not authenticated by the service. ---> System.ServiceModel.FaultException: The request for security token could not be satisfied because authentication failed.

This is my service 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>

I have consume this service in my MVC web.config like this.

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

Then after I have called service directly from my service project, that was working fine.

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

And also tried with published IP address, that also working fine

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

Only problem when I use published host name(http://www.someurl.net/WcfFullPortal.svc). And I have open this URL in by browser that was working.


Solution

  • just Change Csla.DataPortalClient.WcfProxy to Csla.DataPortalClient.HttpProxy and <add key="CslaDataPortalUrl" value="http://www.someurl.net/WcfFullPortal.svc" /> to <add key="CslaDataPortalUrl" value="http://www.someurl.net/DataPortal/PostAsync" />

    And also add

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

    in Global.asax.cs