我有一个C#.net程序。我在代码段中添加了try / catch,现在遇到通信错误。堆栈跟踪为空,服务器堆栈跟踪在我的代码中未显示任何行,并且内部异常为空。 try / catch中的代码大约100行。如何查明错误源?
直到将try / catch添加到handleShipmentBusinessRules方法中之前,我才注意到此错误。
这是错误消息:
错误消息:通信对象, System.ServiceModel.Channels.ClientFramingDuplexSessionChannel,不能 用于通信,因为它处于故障状态。堆 跟踪:服务器堆栈跟踪:在 System.ServiceModel.Channels.CommunicationObject.ThrowIfDisposedOrNotOpen() 在System.ServiceModel.Channels.OutputChannel.BeginSend(Message 消息,TimeSpan超时,AsyncCallback回调,对象状态) System.ServiceModel.Dispatcher.DuplexChannelBinder.BeginRequest(消息 消息,TimeSpan超时,AsyncCallback回调,对象状态) System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.StartSend(布尔 同步完成) System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.FinishEnsureOpen(IAsyncResult 结果,布尔值已完成) System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.StartEnsureOpen(布尔 同步完成) System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.FinishEnsureInteractiveInit(IAsyncResult 结果,布尔值已完成) System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.StartEnsureInteractiveInit() 在System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.Begin() 在System.ServiceModel.Channels.ServiceChannel.BeginCall(String 操作,布尔型单向操作,ProxyOperationRuntime操作,Object [] ins, TimeSpan超时,AsyncCallback回调,对象asyncState)位于 System.ServiceModel.Channels.ServiceChannel.BeginCall(ServiceChannel 通道,ProxyOperationRuntime操作,Object [] ins,AsyncCallback 回调,对象asyncState) System.Threading.Tasks.TaskFactory
1.FromAsyncImpl[TArg1,TArg2,TArg3](Func
6 beginMethod,Func2 endFunction, Action
1 endAction,TArg1 arg1,TArg2 arg2,TArg3 arg3,对象状态,TaskCreationOptions creationOptions)
在 System.Threading.Tasks.TaskFactory1.FromAsync[TArg1,TArg2,TArg3](Func
6 beginMethod,Func`2 endMethod,TArg1 arg1,TArg2 arg2,TArg3 arg3, 对象状态) System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.CreateGenericTask [T](ServiceChannel 通道,ProxyOperationRuntime操作,对象[] inputParameters)
在 System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.CreateGenericTask(ServiceChannel 通道,ProxyOperationRuntime操作,对象[] inputParameters)
在 System.ServiceModel.Channels.ServiceChannelProxy.TaskCreator.CreateTask(ServiceChannel 通道,IMethodCallMessage方法调用,ProxyOperationRuntime 操作) System.ServiceModel.Channels.ServiceChannelProxy.InvokeTaskService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage 消息)在[0]处抛出异常: System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg,IMessage retMsg) System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData,Int32类型)位于 BusinessLogicLayer.ShipService.IShipService.ShippingMethods_GetByDishbooksCodeAsync(String DishbooksCode),网址为 BusinessLogicLayer.ShipmentsBLL.handleShipmentBusinessRules(船舶, DishbooksOrder dbOrder)内部例外:
这是代码的一部分:
public ShipmentDTO ProcessShipment(ShipAFilterDTO ShipAFilterDTO, bool TestShipment = false, bool RelieveInventory = true, bool AdjustGP = true, bool DeveloperMode = true)
{
try
{
Ship ship = new Ship();
ship = retrieveOrderDataIntoShipObject(ShipAFilterDTO);
ship = shipClient.ProcessShipmentAsync(ship, TestShipment).Result;
}
catch (Exception ex)
{
//Voids the Shipment / Tracking Number, since something went wrong
shipClient.Shipment_VoidByTrackingNumberAsync(ship.TrackingNumber).Wait();
throw;
}
}
private Ship retrieveOrderDataIntoShipObject(ShipAFilterDTO ShipAFilterDTO)
{
using (DishbooksUnitOfWork dbUnitOfWork = new DishbooksUnitOfWork(bllSettings.DishbooksConnectionString))
{
Ship ship = new Ship();
... Get some data here ...
// Populate Ship
ship.Notes = dbOrder.SpecialHandlingNotes + " ";
ship.PackageNumber = 1;
handleShipmentBusinessRules(ship, dbOrder);
return ship;
}
}
private void handleShipmentBusinessRules (Ship ship, DishbooksOrder dbOrder)
{
try
{
if (dbOrder.IsWillCallOrder == true)
{
ship.ShippingCarrier = ShippingCarriers.Manual;
ship.ShippingMethodCode = ShippingMethods.ManualShip;
ship.Notes += "Will-Call - Please Take to NT Front-Desk ";
}
else if (dbOrder.IsFreight == true || (!string.IsNullOrEmpty(dbOrder.RequestedShipper) && dbOrder.RequestedShipper.ToUpper() == "FREIGHT"))
{
ship.ShippingCarrier = ShippingCarriers.Manual;
ship.ShippingMethodCode = ShippingMethods.ManualShip;
ship.Notes += "Freight Order - Please Take to Freight Shipping Area ";
}
... Additional populating of ship object
}
catch (Exception ex)
{
logger.Error(@"Error in ShipmentsBLL.cs/handleShipmentBusinessRules." +
Environment.NewLine + "Error Message: " + ex.Message +
Environment.NewLine + "Stack trace: " + ex.StackTrace +
Environment.NewLine + "Inner exception: " + ex.InnerException);
throw;
}
}
Ship类来自第三方工具,该工具接收从其传递的信息并打印运输标签。