我尝试动态设置FTP位置的输出文件夹。 分配,我需要为每个客户创建一个单独的文件夹来存储Excel文件和/或XML文件。
我尝试了什么
我注意到了什么:
当我通过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;
}
修改
经过多次尝试后,这种情况发生了变化。 当我尝试通过静态SendPort动态发送时,我保持相同的问题。 当我尝试动态发送动态SendPort时,我得到了不同的错误:
内部异常:分配给属性' 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;
答案 0 :(得分:1)
从您提供的代码段中,您可以查看以下行。
PublishArticleMessagePort(Microsoft.XLANGs.BaseTypes.Address) = "FTPURI";
您已将 FTPURI 声明为变量,并为地址指定常量字符串。这可能解释了错误 -
内部异常:分配给属性' Microsoft.XLANGs.BaseTypes.Address'无效:' FTP URI'。
答案 1 :(得分:0)
当覆盖静态发送端口属性时,必须让适配器知道它应该使用消息属性而不是端口属性。
将IsDynamicSend属性设置为true
inmsg.Context.Promote("IsDynamicSend", "http://schemas.microsoft.com/BizTalk/2003/system-properties", true);