Biztalk可以运行控制台应用程序吗?

时间:2021-05-24 02:14:58

I am writing a C# console application that takes a binary file, rips it apart, analyzes it, and stores the data into a database.

我正在编写一个C#控制台应用程序,它接受一个二进制文件,将其分开,分析它,并将数据存储到数据库中。

We want to use BizTalk to orchestrate watching when a new binary file is placed in a directory and calling my application with the file name/names to be parsed.

我们希望使用BizTalk来协调在将新的二进制文件放在目录中并使用要解析的文件名/名称调用我的应用程序时进行观察。

Can BizTalk run a command line program?
Can it pass command line parameters to the program?
How would I report back to BizTalk that the last run was a success or a failure?

BizTalk可以运行命令行程序吗?它可以将命令行参数传递给程序吗?我如何向BizTalk报告上次运行是成功还是失败?

Thank you,
Keith

谢谢,基思

3 个解决方案

#1


3  

I would not recommend doing this but in theory you could run the exe using a shell command within an expression shape:

我不建议这样做但理论上你可以在表达式形状中使用shell命令运行exe:

System.Diagnostics.Process.Start(@"C:\yourPath\yourExecutable.exe")

The System.Diagnostics namespace is available in BizTalk 2006, I don't think it is available in BizTalk 2004 (BizTalk 2004 had a very restricted subset of the System namespace available).

System.Diagnostics命名空间在BizTalk 2006中可用,我不认为它在BizTalk 2004中可用(BizTalk 2004有一个非常有限的System命名空间子集可用)。

I'm not sure about getting return values back but you should certainly be able to provide parameters.

我不确定返回值,但你当然应该能够提供参数。

Some references on C# shell commands can be found here and here.

有关C#shell命令的一些参考资料可以在这里和这里找到。

I personally think there are three better options available to you:

我个人认为有三种更好的选择:

  1. Don't use BizTalk.

    不要使用BizTalk。

    As Campbell suggests, use a windows service instead.

    正如Campbell建议的那样,使用Windows服务。

    Only use BizTalk for something like this if you want to leverage an already existing BizTalk framework (logging, reporting etc...) or if you have other tasks in a workflow that BizTalk is going to perform. (There are arguments for putting everything into one platform - if you use BizTalk for one thing, use if for everything, but that is a different conversation).

    如果您想利用已经存在的BizTalk框架(日志记录,报告等等),或者如果您在BizTalk将要执行的工作流程中有其他任务,则仅使用BizTalk这样的事情。 (有将所有内容放在一个平台上的论据 - 如果你将BizTalk用于一件事,那么就可以使用if,但这是一个不同的对话)。

  2. Refactor the logic of your shredder into a C# class library that both your Console application and BizTalk can call.

    将您的碎纸机的逻辑重构为您的控制台应用程序和BizTalk都可以调用的C#类库。

    Calling a class library from BizTalk is much easier to do cleanly and robustly that calling an executable would be.

    从BizTalk调用类库比调用可执行文件更容易干净,更健壮。

    Simply reference your signed and GACed assembly from an orchestration (create it as an orchestration variable) and you can then call it directly from an expression shape.

    只需从业务流程中引用已签名和GACed程序集(将其创建为业务流程变量),然后可以直接从表达式形状中调用它。

    here is an article on this that covers the basics. It doesn't go into a lot of the ugly detail or offer discussion on best practices. Professional BizTalk Server 2006 is a good book for that.

    这是一篇关于基础知识的文章。它没有涉及很多丑陋的细节或提供关于最佳实践的讨论。专业的BizTalk Server 2006是一本很好的书。

  3. As Campbell said, most of this can probably be done with pure BizTalk functionality.

    正如Campbell所说,大部分内容可能都是使用纯BizTalk功能完成的。

I think perhaps a mix of options 2 and 3 would be best for what you want. Put the binary shredding logic you already have into a C# class library and call this from within a BizTalk orchestration that takes care of your file monitoring, error notification, tracking and integration with other processes.

我想也许选项2和3的混合最适合你想要的。将已有的二进制碎化逻辑放入C#类库,并在BizTalk业务流程中调用它,负责文件监控,错误通知,跟踪以及与其他进程的集成。

#2


1  

Biztalk is a server product so it will always be running in the background when you set it up in a production environment.

Biztalk是一种服务器产品,因此当您在生产环境中进行设置时,它将始终在后台运行。

I'd suggest that if you're wanting to use BizTalk you set it up to watch the location where the file will be dropped, rip it apart, analyze it and then write out to the database all within a BizTalk workflow. Its exactly what it's been designed to do. The workflow could also contain notifications or you could just use BizTalk tracking to confirm if the operation has been successful. The only custom code you might need to write is a disassembler for your binary file to turn it into XML. This would be done as a receive pipeline component.

我建议如果你想使用BizTalk,你可以设置它来查看文件将被删除的位置,将其分开,分析它然后在BizTalk工作流程中写出数据库。它正是它的设计目标。工作流还可以包含通知,或者您可以使用BizTalk跟踪来确认操作是否成功。您可能需要编写的唯一自定义代码是二进制文件的反汇编程序,可将其转换为XML。这将作为接收管道组件完成。

If that's all your doing though, BizTalk is a heck of an expensive option for just this. I suggest you write your own Windows service and use the FileSystemWatcher to intercept the fact that a file has been written and then do the processing in your C# code.

如果这就是你所做的一切,那么BizTalk就是一个昂贵的选择。我建议您编写自己的Windows服务并使用FileSystemWatcher拦截文件已写入的事实,然后在C#代码中进行处理。

#3


1  

BizTalk calling a C# application is kind of out if its box. We've had issues like this in the past and we have the console applications written or wrapped as a web service. This way, Biztalk picks up the file being dropped off and sends it to the app web service application. This falls under the 'swiss army knife' portion of how we use BizTalk. This is really underkill. However, BizTalk does provide things like tracking, BAM, queueing for farside failures, etc. We additionally have gotten into copying files to archive locations, reading result codes from web services and using the SMTP adapter to send notification of success or failure.

调用C#应用程序的BizTalk有点像它的盒子。我们过去遇到过这样的问题,我们将控制台应用程序编写或包装为Web服务。这样,Biztalk会获取正在删除的文件并将其发送到应用程序Web服务应用程序。这属于我们如何使用BizTalk的“瑞士军刀”部分。这真是一种杀手锏。但是,BizTalk确实提供了跟踪,BAM,远程故障排队等功能。我们还将文件复制到存档位置,从Web服务读取结果代码并使用SMTP适配器发送成功或失败通知。

Hope this gives you some ideas. Best of luck!

希望这会给你一些想法。祝你好运!

#1


3  

I would not recommend doing this but in theory you could run the exe using a shell command within an expression shape:

我不建议这样做但理论上你可以在表达式形状中使用shell命令运行exe:

System.Diagnostics.Process.Start(@"C:\yourPath\yourExecutable.exe")

The System.Diagnostics namespace is available in BizTalk 2006, I don't think it is available in BizTalk 2004 (BizTalk 2004 had a very restricted subset of the System namespace available).

System.Diagnostics命名空间在BizTalk 2006中可用,我不认为它在BizTalk 2004中可用(BizTalk 2004有一个非常有限的System命名空间子集可用)。

I'm not sure about getting return values back but you should certainly be able to provide parameters.

我不确定返回值,但你当然应该能够提供参数。

Some references on C# shell commands can be found here and here.

有关C#shell命令的一些参考资料可以在这里和这里找到。

I personally think there are three better options available to you:

我个人认为有三种更好的选择:

  1. Don't use BizTalk.

    不要使用BizTalk。

    As Campbell suggests, use a windows service instead.

    正如Campbell建议的那样,使用Windows服务。

    Only use BizTalk for something like this if you want to leverage an already existing BizTalk framework (logging, reporting etc...) or if you have other tasks in a workflow that BizTalk is going to perform. (There are arguments for putting everything into one platform - if you use BizTalk for one thing, use if for everything, but that is a different conversation).

    如果您想利用已经存在的BizTalk框架(日志记录,报告等等),或者如果您在BizTalk将要执行的工作流程中有其他任务,则仅使用BizTalk这样的事情。 (有将所有内容放在一个平台上的论据 - 如果你将BizTalk用于一件事,那么就可以使用if,但这是一个不同的对话)。

  2. Refactor the logic of your shredder into a C# class library that both your Console application and BizTalk can call.

    将您的碎纸机的逻辑重构为您的控制台应用程序和BizTalk都可以调用的C#类库。

    Calling a class library from BizTalk is much easier to do cleanly and robustly that calling an executable would be.

    从BizTalk调用类库比调用可执行文件更容易干净,更健壮。

    Simply reference your signed and GACed assembly from an orchestration (create it as an orchestration variable) and you can then call it directly from an expression shape.

    只需从业务流程中引用已签名和GACed程序集(将其创建为业务流程变量),然后可以直接从表达式形状中调用它。

    here is an article on this that covers the basics. It doesn't go into a lot of the ugly detail or offer discussion on best practices. Professional BizTalk Server 2006 is a good book for that.

    这是一篇关于基础知识的文章。它没有涉及很多丑陋的细节或提供关于最佳实践的讨论。专业的BizTalk Server 2006是一本很好的书。

  3. As Campbell said, most of this can probably be done with pure BizTalk functionality.

    正如Campbell所说,大部分内容可能都是使用纯BizTalk功能完成的。

I think perhaps a mix of options 2 and 3 would be best for what you want. Put the binary shredding logic you already have into a C# class library and call this from within a BizTalk orchestration that takes care of your file monitoring, error notification, tracking and integration with other processes.

我想也许选项2和3的混合最适合你想要的。将已有的二进制碎化逻辑放入C#类库,并在BizTalk业务流程中调用它,负责文件监控,错误通知,跟踪以及与其他进程的集成。

#2


1  

Biztalk is a server product so it will always be running in the background when you set it up in a production environment.

Biztalk是一种服务器产品,因此当您在生产环境中进行设置时,它将始终在后台运行。

I'd suggest that if you're wanting to use BizTalk you set it up to watch the location where the file will be dropped, rip it apart, analyze it and then write out to the database all within a BizTalk workflow. Its exactly what it's been designed to do. The workflow could also contain notifications or you could just use BizTalk tracking to confirm if the operation has been successful. The only custom code you might need to write is a disassembler for your binary file to turn it into XML. This would be done as a receive pipeline component.

我建议如果你想使用BizTalk,你可以设置它来查看文件将被删除的位置,将其分开,分析它然后在BizTalk工作流程中写出数据库。它正是它的设计目标。工作流还可以包含通知,或者您可以使用BizTalk跟踪来确认操作是否成功。您可能需要编写的唯一自定义代码是二进制文件的反汇编程序,可将其转换为XML。这将作为接收管道组件完成。

If that's all your doing though, BizTalk is a heck of an expensive option for just this. I suggest you write your own Windows service and use the FileSystemWatcher to intercept the fact that a file has been written and then do the processing in your C# code.

如果这就是你所做的一切,那么BizTalk就是一个昂贵的选择。我建议您编写自己的Windows服务并使用FileSystemWatcher拦截文件已写入的事实,然后在C#代码中进行处理。

#3


1  

BizTalk calling a C# application is kind of out if its box. We've had issues like this in the past and we have the console applications written or wrapped as a web service. This way, Biztalk picks up the file being dropped off and sends it to the app web service application. This falls under the 'swiss army knife' portion of how we use BizTalk. This is really underkill. However, BizTalk does provide things like tracking, BAM, queueing for farside failures, etc. We additionally have gotten into copying files to archive locations, reading result codes from web services and using the SMTP adapter to send notification of success or failure.

调用C#应用程序的BizTalk有点像它的盒子。我们过去遇到过这样的问题,我们将控制台应用程序编写或包装为Web服务。这样,Biztalk会获取正在删除的文件并将其发送到应用程序Web服务应用程序。这属于我们如何使用BizTalk的“瑞士军刀”部分。这真是一种杀手锏。但是,BizTalk确实提供了跟踪,BAM,远程故障排队等功能。我们还将文件复制到存档位置,从Web服务读取结果代码并使用SMTP适配器发送成功或失败通知。

Hope this gives you some ideas. Best of luck!

希望这会给你一些想法。祝你好运!