1

我正在尝试动态设置 FTP 位置的输出文件夹。分配,我需要为每个客户创建一个单独的文件夹来存储 Excel 文件和/或 XML 文件。

我试过的

  • 创建了一个自定义管道组件以将所有必需的属性设置为 FTP 发送端口。
  • 尝试将相同的管道连接到动态发送端口
  • 为了测试,尝试了编排中的代码。

我注意到了什么:

当我通过 FTP 发送端口发送时,自定义管道属性不会覆盖这些属性。

当我通过动态发送时,我总是收到以下错误

传输消息时遇到故障

即使我尝试将属性设置到 Orchestration 中,我也会遇到同样的错误。

此外,当我尝试通过动态发送端口发送时,我注意到管道组件没有被触及。

执行自定义管道组件的代码部分

public IBaseMessage Execute(IPipelineContext pipelineContext, IBaseMessage inputMessage)
    {
        Guid callToken = TraceManager.PipelineComponent.TraceIn(CLASSNAME + ".Execute() - Start", pipelineContext.PipelineID, pipelineContext.PipelineName, pipelineContext.StageID);

        if (!this.Active)
        {
            TraceManager.PipelineComponent.TraceOut(callToken, CLASSNAME + ".Execute() - Pipeline component is not active!");
            return inputMessage;
        }

        try
        {
            string completeFTPUri = null;
            string fileName = null;
            string accountNumber = Convert.ToString(inputMessage.Context.Read(PROP_ACCOUNTNUMBER.Name.Name, PROP_ACCOUNTNUMBER.Name.Namespace));

            if (!string.IsNullOrWhiteSpace(accountNumber))
                this.Folder = string.Format("{0}/{1}", this.Folder, accountNumber);

            if (!string.IsNullOrWhiteSpace(this.Folder))
                completeFTPUri = string.Format("ftp://{0}:21/{1}", this.FTPUri, this.Folder);
            else
                completeFTPUri = this.FTPUri;

            if (!UseDefaultFilename)
            {
                string receiveFilename = null;
                receiveFilename = Convert.ToString(inputMessage.Context.Read(FTP_RECEIVED_FILENAME.Name.Name, FTP_RECEIVED_FILENAME.Name.Namespace));

                if (!string.IsNullOrWhiteSpace(receiveFilename))
                    fileName = Path.GetFileName(receiveFilename);
            }

            if (string.IsNullOrWhiteSpace(fileName))
            {
                if (string.IsNullOrWhiteSpace(this.Filename))
                    fileName = DEFAULT_FILENAME;
                else
                    fileName = this.Filename;
            }

            if (fileName.Contains("{0") || fileName.Contains("{1"))
            {
                fileName = string.Format(fileName, DateTime.Now, inputMessage.MessageID);
            }

            if (!string.IsNullOrWhiteSpace(this.Folder))
            {
                //inputMessage.Context.Write(FTP_BEFORE_PUT.Name.Name, FTP_BEFORE_PUT.Name.Namespace, string.Format("MKDIR {0}", string.Format("ftp://{0}:21/{1}", this.FTPUri, this.Folder)));
                inputMessage.Context.Promote(FTP_BEFORE_PUT.Name.Name, FTP_BEFORE_PUT.Name.Namespace, string.Format("MKDIR {0}", completeFTPUri));
            }

            //inputMessage.Context.Write(OUTBOUND_TRANSPORT_LOCATION.Name.Name, OUTBOUND_TRANSPORT_LOCATION.Name.Namespace, completeFTPUri);
            //inputMessage.Context.Write(FILE_RECEIVED_FILENAME.Name.Name, FILE_RECEIVED_FILENAME.Name.Namespace, fileName);
            //inputMessage.Context.Write(FTP_USERNAME.Name.Name, FTP_USERNAME.Name.Namespace, _userName);
            //inputMessage.Context.Write(FTP_PASSWORD.Name.Name, FTP_PASSWORD.Name.Namespace, _password);
            inputMessage.Context.Promote(OUTBOUND_TRANSPORT_LOCATION.Name.Name, OUTBOUND_TRANSPORT_LOCATION.Name.Namespace, completeFTPUri);
            inputMessage.Context.Promote(OUTBOUND_TRANSPORT_TYPE.Name.Name, OUTBOUND_TRANSPORT_TYPE.Name.Namespace, "FTP");
            inputMessage.Context.Promote(FILE_RECEIVED_FILENAME.Name.Name, FILE_RECEIVED_FILENAME.Name.Namespace, fileName);
            inputMessage.Context.Promote(FTP_USERNAME.Name.Name, FTP_USERNAME.Name.Namespace, this.UserName);
            inputMessage.Context.Promote(FTP_PASSWORD.Name.Name, FTP_PASSWORD.Name.Namespace, this.Password);

        }
        catch (Exception ex)
        {
            TraceManager.PipelineComponent.TraceError(ex, false, callToken);
            throw new Exception(CLASSNAME + ".Execute() - Failed to set the filename.", ex);
        }

        TraceManager.PipelineComponent.TraceOut(callToken, CLASSNAME + ".Execute() - Finished.");
        return inputMessage;
    }

编辑:

在尝试了很多之后,这次更新。当我尝试通过静态发送端口动态发送时,我仍然遇到同样的问题。当我尝试通过动态发送端口动态发送时,我遇到了不同的错误:

内部异常:分配给属性“Microsoft.XLANGs.BaseTypes.Address”的值无效:“FTP URI”。

我不知道解决此问题的最佳解决方案是什么。我还可以将所有内容写入帮助程序类,然后尝试通过 C# 代码发送。但我想使用 BizTalk 的力量,并希望能够在必要时启用 en 禁用端口。这是主要原因。我不害怕编写自定义管道组件或其他东西,所以如果有人可以提供帮助。请

编排的消息分配代码

MsgPublishArticleMessage = MsgFullArticleMessage;
MsgPublishArticleMessage(*) = MsgFullArticleMessage(*);

MsgPublishArticleMessage(DOMAIN.BizTalk.Common.Schemas.Domain) = "ArticleMessage";
MsgPublishArticleMessage(DOMAIN.BizTalk.Common.Schemas.Service) = "PricatService";
MsgPublishArticleMessage(DOMAIN.BizTalk.Common.Schemas.Action) = "PublishPricatXLSX";
MsgPublishArticleMessage(DOMAIN.BizTalk.Common.Schemas.Version) = "1.0";
MsgPublishArticleMessage(DOMAIN.BizTalk.Common.Schemas.AccountNumber) = articleMessageRequest.AccountNumber;
MsgPublishArticleMessage(BTS.OutboundTransportLocation) = "ftp://URI:21/Pricat/" + articleMessageRequest.AccountNumber;
MsgPublishArticleMessage(BTS.OutboundTransportType) = "FTP";
MsgPublishArticleMessage(FTP.Password) = "********";
MsgPublishArticleMessage(FTP.UserName) = "UserName";
MsgPublishArticleMessage(FTP.BeforePut) = "MKDIR " + articleMessageRequest.AccountNumber;
MsgPublishArticleMessage(FTP.ReceivedFileName) = Destil.BizTalk.ArticleMessage.Components.OrchestrationHelper.CreateReceivedFileName(articleMessageRequest, ".xlsx");
PublishArticleMessagePort(Microsoft.XLANGs.BaseTypes.Address) = "FTPURI";
PublishArticleMessagePort(Microsoft.XLANGs.BaseTypes.TransportType) = "FTP";
MsgPublishArticleMessage(BTS.IsDynamicSend) = true;

编辑2:

当我将消息分配更改为以下代码时,我可以将文件发送到动态文件夹。我现在遇到的唯一问题:当文件夹已经存在时,我遇到了失败。

有谁知道只有当文件夹不存在时我才需要使用什么 FTP 命令来创建文件夹?我尝试了以下命令

MDK -p /Pricat/AccountNumber;
MDK /Pricat/AccountNumber;
如果不存在 "/Pricat/AccountNumber" MDK /Pricat/AccountNumber

在编排中更改了消息分配的代码

MsgPublishArticleMessage = MsgFullArticleMessage;
MsgPublishArticleMessage(*) = MsgFullArticleMessage(*);

MsgPublishArticleMessage(DOMAIN.BizTalk.Common.Schemas.Domain) = "ArticleMessage";
MsgPublishArticleMessage(DOMAIN.BizTalk.Common.Schemas.Service) = "PricatService";
MsgPublishArticleMessage(DOMAIN.BizTalk.Common.Schemas.Action) = "PublishPricatXLSX";
MsgPublishArticleMessage(DOMAIN.BizTalk.Common.Schemas.Version) = "1.0";
MsgPublishArticleMessage(DOMAIN.BizTalk.Common.Schemas.AccountNumber) = articleMessageRequest.AccountNumber;
MsgPublishArticleMessage(BTS.OutboundTransportLocation) = "ftp://URI:21/Pricat/" + articleMessageRequest.AccountNumber;
MsgPublishArticleMessage(BTS.OutboundTransportType) = "FTP";
MsgPublishArticleMessage(FTP.Password) = "*********";
MsgPublishArticleMessage(FTP.UserName) = "username";
MsgPublishArticleMessage(FTP.BeforePut) = "MKD Pricat/" + articleMessageRequest.AccountNumber + "; CWD Pricat/" + articleMessageRequest.AccountNumber;
PublishArticleMessagePort(Microsoft.XLANGs.BaseTypes.Address) = "ftp://URI:21/" + DOMAIN.BizTalk.ArticleMessage.Components.OrchestrationHelper.CreateReceivedFileName(articleMessageRequest, ".xlsx");
PublishArticleMessagePort(Microsoft.XLANGs.BaseTypes.TransportType) = "FTP";
MsgPublishArticleMessage(BTS.IsDynamicSend) = true;
4

2 回答 2

1

从您提供的代码段中,您可以检查以下行。

PublishArticleMessagePort(Microsoft.XLANGs.BaseTypes.Address) = "FTPURI";

您已将FTPURI声明为变量,并将常量字符串分配给地址。这可能解释了错误 -

内部异常:分配给属性“Microsoft.XLANGs.BaseTypes.Address”的值无效:“FTP URI”。

于 2018-03-09T00:24:08.020 回答
0

覆盖静态发送端口属性时,您必须让适配器知道它应该使用消息属性而不是端口属性。

将 IsDynamicSend 属性设置为 true

inmsg.Context.Promote("IsDynamicSend", "http://schemas.microsoft.com/BizTalk/2003/system-properties", true);
于 2018-03-08T08:54:15.087 回答