Microsoft Developer Network > Forums Home > Commerce Server Forums > Commerce Server 2009 > Access Profiles from out of commerce server site
Ask a questionAsk a question
 

Proposed AnswerAccess Profiles from out of commerce server site

  • Thursday, November 05, 2009 7:04 AMsakthimind Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    Instead of directly accessing the CS API's from CSharp site, we are trying to access like created website and WCF services. From WCF services we are trying to access the CS API and consuming the WCF services in website.

    While trying to login, ie. to create on profile object, it is showing error in the following line

    Profile userProfile = CommerceContext.Current.ProfileSystem.GetProfile(UserLoginPropertyName, userid, UserProfileName);

    Error message: Object reference not set to an instance of an object.


    But the same code is working fine in CSharp site.

    Can any one help me how to access from out of commerce server site

    Regards,
    Sakthivel.S

All Replies

  • Thursday, November 05, 2009 9:44 AMLewisBenge Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    Have you got all the necessary HTTP modules installed in your web.config file?

    You may also be better off using the 2009 Commerce Foundation API for WCF too, as the entity models, and fault handling are better suited to WCF>

    Thanks,
    Lewis
    Follow Me on Twitter: @LewisBenge Or check out my blog: http://www.geekswithblogs.com/pointtoshare/
  • Thursday, November 05, 2009 9:53 AMRavi Kanth KoppalaMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer
    Make sure your WCF service have the same web.config entries as CSharp site. It seems web.config is not having HTTP handlers and when you try to instantiate the object, it is throwning object reference error.

    Hope this helps.

    Regards,
    -Ravi Kanth Koppala
    http://techblog.ravikanth.net (If this post answers your question - Either Mark this post as the answer or vote as being useful.)
  • Thursday, November 05, 2009 1:15 PMIanRae - CS Product Team Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    You will probably also need to use WCF's aspNetCompatibilityEnabled in order for HttpModules and HttpContext to work.  http://blogs.msdn.com/wenlong/archive/2006/01/23/516041.aspx
  • Thursday, November 05, 2009 4:43 PMMatt Furnari Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    I have had this problem before also. When you are using the CSharp site the runtime automatically creates the CommerceContext objects for you. But when you moved to WCF those contexts became null. Here is a quick fix that works for both cases:

    ProfileContext oProfileSystem = null;
    if (null == CommerceContext.Current)
        oProfileSystem = new ProfileContext(Constants.ProfileConnectionString, new ConsoleDebugContext(DebugMode.Checked));
    else
        oProfileSystem = CommerceContext.Current.ProfileSystem;
    
    Profile userProfile = oProfileSystem.GetProfile(UserLoginPropertyName, userid, UserProfileName);
    

    The WCF service will see CommerceContext.Current == null and create a new one. 

    Good Luck,
    Matt Furnari