Error happens on OrderContext when use WCF service

Vote:
 

Under the commerce site, i want to expose some data to the other party by WCF service.

it give me the error :

at Mediachase.BusinessFoundation.Data.Sql.SqlCommandBuilder..ctor(String table)

   at Mediachase.BusinessFoundation.Data.Sql.SelectCommandBuilder..ctor(String tableName, FilterElementCollection filters, SortingElementCollection sorting)

   at Mediachase.BusinessFoundation.Data.DataHelper.List(String tableName, Int32 maxCount, FilterElementCollection filters, SortingElementCollection sorting)

   at Mediachase.BusinessFoundation.Data.DataHelper.List(String tableName, Int32 maxCount, FilterElement[] filters)

   at Mediachase.BusinessFoundation.Data.DataHelper.List(String tableName, FilterElement[] filters)

   at Mediachase.Commerce.Orders.Managers.Sql.OrderGroupNote_row.List(FilterElement[] filters)

   at Mediachase.Commerce.Orders.OrderNoteCollection.LoadOrderNotes()

   at Mediachase.Commerce.Orders.OrderGroup.PopulateCollections(DataTableCollection tables, String filter)

   at Mediachase.Commerce.Orders.PurchaseOrder.PopulateCollections(DataTableCollection tables, String filter)

   at Mediachase.Commerce.Orders.OrderGroup.PopulateCollection[T](ClassInfo classInfo, MetaStorageCollectionBase`1 collection, DataSet dataSet)

   at Mediachase.Commerce.Orders.PurchaseOrder.Search(OrderSearch search, Int32& totalRecords)

   at Mediachase.Commerce.Orders.OrderContext.FindPurchaseOrders(OrderSearchParameters parameters, OrderSearchOptions options, Int32& totalRecords)

   at Mediachase.Commerce.Orders.OrderContext.FindPurchaseOrders(OrderSearchParameters parameters, OrderSearchOptions options)

   at JBHiFi.CMS.Web.Helpers.Commerce.OrderGroupCommerceHelper.GetOrders(Nullable`1 start, Nullable`1 end, Nullable`1 orderId, Nullable`1 status) in c:\Work\JBHiFi\JBHifi.com.au\trunk\source\JBHiFi.CMS.Web.Helpers\Commerce\OrderGroupCommerceHelper.cs:line 39

   at JBHiFi.CMS.Web.Repository.OrderGroups.OrderRepository.GetOrders(Nullable`1 start, Nullable`1 end, Nullable`1 orderId, Nullable`1 status) in c:\Work\JBHiFi\JBHifi.com.au\trunk\source\JBHiFi.CMS.Web.Repository\OrderGroups\OrderRepository.cs:line 188

   at JBHiFi.CMS.Web.Business.Integration.FulFilmentService.FormOrdersFromCarts(Nullable`1 start, Nullable`1 end, Nullable`1 orderId, Nullable`1 status) in c:\Work\JBHiFi\JBHifi.com.au\trunk\source\JBHiFi.CMS.Web.Business\Integration\FulFilmentService.cs:line 40

   at JBHiFi.CMS.Web.Services.OrderService.GetOrders(Nullable`1 start, Nullable`1 end, Nullable`1 orderId, Nullable`1 status) in c:\Work\JBHiFi\JBHifi.com.au\trunk\source\JBHiFi.CMS.Web.Services\OrderService.svc.cs:line 22

   at SyncInvokeGetOrders(Object , Object[] , Object[] )

   at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)

   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)

 

this error only happens when i try to call the order repository in wcf, I have a test page /handlers/TestCustomer.ashx, the order repository works fine, the commerce site have share all the same configs/web.config files.

 

can anyone have the same issue as me in this case? 

 

#73413
Jul 19, 2013 5:41
Vote:
 

Probably the SqlContext and/or DataContext are null? This can also happen when you use a scheduled job e.g.

try adding this before calling the order repository:

if (SqlContext.Current == null)
                {
                    SqlContext.Current = new SqlContext(ConfigurationManager.ConnectionStrings["EcfSqlConnection"].ConnectionString);
                }
 
                if (DataContext.Current == null)
                {
                    DataContext.Current = new DataContext(ConfigurationManager.ConnectionStrings["EcfSqlConnection"].ConnectionString);
                }

 

#73424
Jul 19, 2013 15:35
Vote:
 

Thanks Jeroen, that solved my issue.

#73436
Jul 22, 2013 1:53
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.