biztalk 2006 R2 中的异常处理
我有一个 Biztalk 2006 R2 项目(与 ESB 指南 1 一起使用) 我正在从编排调用 C# 代码中的静态方法,该方法使用一个类将文件数据加载到第 0 部分的 xlang 消息正文中 当我传递不存在的文件路径时,内部类捕获异常但不抛出它(在静态方法中有一个 catch 块,在编排中有对异常的真正处理)
静态方法是:
public static XLANGMessage LoadFileIntoMessage(XLANGMessage message, string filePath,Encoding encoding)
{
try
{
IStreamFactory sf = new FileStreamFactory(filePath,encoding);
message[0].LoadFrom(sf);
return message;
}
catch (Exception ex)
{
throw ex;
}
}
加载文件流的类是:
private class FileStreamFactory : IStreamFactory
{
string _fname;
Encoding _encoding;
public FileStreamFactory(string fname,Encoding encoding)
{
_fname = fname;
_encoding = encoding;
}
public Stream CreateStream()
{
try
{
StreamReader sr;
sr = new StreamReader
(
_fname,
_encoding
);
return sr.BaseStream;
}
catch (Exception ex)
{
throw ex;
}
}
}
我从编排中调用静态方法,并期望在类和方法获取它之后捕获编排中的异常。
I have a Biztalk 2006 R2 project (used with ESB Guidance 1)
I am calling from orchstration to a static method in c# code, this method uses a class to load a file data into xlang message body at part 0
When I pass filepath which doesn't exist the inside class catch the exception but don't throw it up (in the static method there is a catch block and in the orchstration there is the real handling of the exception)
The static method is:
public static XLANGMessage LoadFileIntoMessage(XLANGMessage message, string filePath,Encoding encoding)
{
try
{
IStreamFactory sf = new FileStreamFactory(filePath,encoding);
message[0].LoadFrom(sf);
return message;
}
catch (Exception ex)
{
throw ex;
}
}
The Class which load the file stream is :
private class FileStreamFactory : IStreamFactory
{
string _fname;
Encoding _encoding;
public FileStreamFactory(string fname,Encoding encoding)
{
_fname = fname;
_encoding = encoding;
}
public Stream CreateStream()
{
try
{
StreamReader sr;
sr = new StreamReader
(
_fname,
_encoding
);
return sr.BaseStream;
}
catch (Exception ex)
{
throw ex;
}
}
}
I call the static method from the orchestration and expect to catch the exception in my orchestration after the class and the method gets it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这里的实际问题是什么......您是在谈论如何捕获编排中的异常吗?如何让它进入ESB异常处理系统或者什么?
要处理编排中的异常,您需要使用范围形状(在其中放入可以引发异常的代码/形状),然后向其添加异常处理程序(有点像 try/catch 块)。
有关 ESB 的内容,请参见此处: http:// /msdn.microsoft.com/en-US/library/ee250235(v=BTS.10).aspx
最后,请允许我说:请不要像您在代码中所做的那样处理异常。您不应该捕获异常只是为了再次抛出它。这是一种非常糟糕的编程实践,它会损害性能,还会导致您丢失异常的原始堆栈跟踪,从而使诊断和解决任何问题变得更加困难。请参阅http://winterdom.com/2002/09/rethroingexceptionsinc
I'm not sure what the actual question here is.... are you talking about how to catch the exception in the orchestration? How to make it go into the ESB Exception Handling system or what?
To handle an exception in an orchestration you need to use a Scope shape (where you put in the code/shapes that can throw the exception) and then add a Exception handler to it (kinda like a try/catch block).
For the ESB stuff, see here: http://msdn.microsoft.com/en-US/library/ee250235(v=BTS.10).aspx
Finally, allow me to say: Please do NOT handle exceptions as you're doing in your code already. You should NOT catch a exception just to throw it again. It's a very poor programming practice, it hurts performance and it will also cause you to lose the original stack trace of the exception, making it harder to diagnose and solve any issues. See http://winterdom.com/2002/09/rethrowingexceptionsinc