Sometimes we may need to read some files from various of sources but the BizTalk File adapter doesn’t natively support ‘Dynamic Receive’. In other words, we cannot use File adapter on a two-way send port whose URIs can be changed in orchestrtion code.
Then how can achieve such goal?
A workable approach is that we can write a .net class to call BizTalk WMI provider to modify the URL of a receive location. The code can be very simple as below:
publicvoid SetFileAddress(string FileAddress)
ReceivePortCollection ReceivePorts = BizTalkCatalog.ReceivePorts;
ReceiveLocation ReceiveLocation = ReceivePorts[“DynamicReceivePort”].ReceiveLocations[“DynamicReceiveRL”];
ReceiveLocation.Address = FileAddress;
ReceiveLocation.Enable = true;
However, the challenge is on multi-threading/multiple instance part. You will find such WMI operations cannot handle muti-threading situation. This means if there are many concurrent calls to the WMI provider, most of the calls will fail or ever worse, the invokers will cause WMI service instance(WmiPrvSE.exe) crash… and unexpected hang of BizTalk Admin console. So the most important part is that we must implement a singleton convoy/pattern in our orchestration to avoid concurrent calls. A good example can be found at:
Implementing Singleton pattern with BizTalk Orchestrations