开发者

Create a File in a Biztalk message inside a orchestration

开发者 https://www.devze.com 2022-12-14 20:05 出处:网络
I\'m having some trouble sending a file by ftp from my BizTalk 2006RC. The part the i struggle is to create a real file named \"OPA0037\" with only one line

I'm having some trouble sending a file by ftp from my BizTalk 2006RC. The part the i struggle is to create a real file named "OPA0037" with only one line

"OPA0037;TEST;;;"

that it after the ftp part isn't a problem i juste don't see how to create a file from a message... It can only be in the orchestration.

any help any idea is welcomed! than开发者_Python百科ks alot!!


It isn't clear exaclty what you are having trouble with here so I'm going to go over each step you describe and cover the various options. Hopefully one of these points addresses your problem.

The post got quite involved as I kept thinking of possible extra issues - I suspect the key section for you will be the last one Sending a message using the FTP transport in BizTalk

Let us know how you get along...

Creating a FlatFile message within an orchestration

In BizTalk you never create orchestration messages in any format other than XML.

What you need to do to create a FlatFile message from within a BizTalk orchestration is to create a FlatFile schema at design time and then at runtime, generate an instance of this schema and send it out through a BizTalk send port that has the BizTalk FlatFile assembler configured in the assemble stage.

A FlatFile schema is simply an XML schema with special annotations that inform the BizTalk FlatFile assembler how to serialize XML to text.

So, creating a FlatFile message within an orchestration is actually the same as creating any other document format within an orchestration.

Creating a message within an orchestration

So then, how to create a new message within a BizTalk orchestration?

To avoid recreating the wheel, here is a link to a rather classic post by Matt Meleski about just this topic.

To summarise what Matt says, to create a new instance of a message in BizTalk you have four main options available to you:

  1. Create a new message from an existing message using a BizTalk map
  2. Assign one message from another message within a Message Assignment shape
  3. Utilise an XML.XMLDocument variable within a Message Assignment shape.
  4. Use a .NET helper class that returns a message of the required type.

As with most things, each of the options above could have its own lengthy post written about it.

Probably for your case of needing to create a simple one line document, either the mapping option (1) or the XMLDocument option (3) will get you where you need to go.

Sending a message using the FTP transport in BizTalk

I think this could be your problem - how to send an FTP message, or FlatFile format in BizTalk with a specified filename.

There are a number of approaches to this. I'll give two, hopefully the first should work but you can then fall back to the second.

1. Set the ReceivedFileName and use the %SourceFileName% macro

While researching my answer, I didn't think that this approach would work for FTP, but I found a production example where I'm doing just this. Give it a go.

In the orchestration Construct Message shape, add a Message Assignment shape.

In that message assignment shape, you can set the FILE.ReceivedFileName property for your flat file message as so:

yourFlatFileMessage(FILE.ReceivedFileName) = whateverFileNameYouWant;

This sets a context property that will then be used when you wire a static send port to your orchestration port. In your static send port you specify the FTP adapter with a target file name like:

%SourceFileName%.txt

And the FTP adapter then replaces the %SourceFileName% macro, giving you a filename like whateverFileNameYouWant.txt

In your send port you then need to specify a send pipeline that contains a FlatFile assembler for your flatfile format.

2. Use a dynamic send port with a programatic call to a pipeline

If the method above doesn't work then you will need to use a dynamic send pipeline.

The problem is that to send a FTP message with a specified file name in BizTalk, you need to use a dynamic send port. BUT with a dynamic send port you are limited to a pass through pipeline, so you have nowhere to specify your FlatFile assembler.

To create a dynamic send port that creates the file name you want to following code in an orchestration message assignment shape (courtesy of Christof Claessens' blog):

//Set dynamic ports location:
orchprtSndMyMessagePort(Microsoft.XLANGs.BaseTypes.Address) = "ftp://myserver/mydirectory/myfilename.xml";

//Set context on the message you want to send:
msgMyMessage(FTP.UserName) = "myFTPUsername";
msgMyMessage(FTP.Password) = "myFTPPassword";
msgMyMessage(BTS.RetryCount) = 20;
msgMyMessage(BTS.RetryInterval) = 2; 

So, how to then make this dynamic send port send out a flatfile format file?

That trick is discussed here. What you need to do call a send pipeline from within an Orchestration (a new capability in BizTalk 2006).

The code to do that is below:

//PipeMsg is a variable of type: Microsoft.XLANGs.Pipeline.SendPipelineInputMessages
PipeMsg = new Microsoft.XLANGs.Pipeline.SendPipelineInputMessages();
PipeMsg.Add(<MessageToAssemble>);
Microsoft.XLANGs.Pipeline.XLANGPipelineManager.ExecuteSendPipeline(typeof    (<fullyQualifiedNameofSendPipline>),PipeMsg,msg_Output_FF);

This then populates your orchestration message msg_OUtput_FF with your FlatFile formatted text. BizTalk still thinks of this as an XML document, but it isn't really. When you send this out through you dynamic send port with its passthrough pipeline, you should see the flatfile contents.


Maybe you can try two of the most common options:

  • Send the message through a send port and configure that port to use the FILE or FTP adapter. If the file is a flat file with delimited structure (as in the sample), you should create the corresponding Flat File Schema and a Send pipeline wich includes the Flat File Assembler in its assemble stage. Then, configure your physical port to use that pipeline.

Look at this walkthrough from msdn on creating Flat Files: http://msdn.microsoft.com/en-us/library/aa577898(BTS.20).aspx

  • Create a .NET class library with the code for writing the physical file and use it from the Orchestration. You´ll neeed to add the class library assembly as a reference to the BTS project.
0

精彩评论

暂无评论...
验证码 换一张
取 消