【问题标题】:Biztalk mapping, creating string[] from stringBiztalk 映射,从字符串创建字符串[]
【发布时间】:2011-10-25 13:19:54
【问题描述】:

在 biztalk 映射中,源模式有一个字符串,而目标模式正在等待一个字符串数组。

我只需要创建一个只有一个字符串的字符串数组,但我做不到。

我尝试使用脚本 functoid 和一些内联 C#:

public Array ArrayBuilder(string param1)
{
    ArrayList result = new ArrayList();
    result.Add(param1);
    return result.ToArray(typeof( string ));
}

但 functoid 输出的不是数组:

...
<recipients>System.String[]</recipients>
...

有什么帮助吗?

谢谢

编辑

源架构

基本上是一个 SMS 列表(ID、消息和电话号码)。通过编排中的循环,我遍历所有 SMS 并准备 SMSSend 消息。列表中的每条短信都会发生这种映射(这就是为什么我有一个计数器)

电话号码是我遇到问题的字符串

<xs:schema xmlns:tns="http://schemas.datacontract.org/2004/07/ADOSybaseWCFServices" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/ADOSybaseWCFServices" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="SMSBatch">
    <xs:sequence>
        <xs:element name="IDBatch" type="xs:int" /> 
        <xs:element name="SMSList" nillable="true" type="tns:ArrayOfSMS" /> 
    </xs:sequence>
</xs:complexType>
<xs:element name="SMSBatch" nillable="true" type="tns:SMSBatch" />
<xs:complexType name="ArrayOfSMS">
    <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" name="SMS" nillable="true" type="tns:SMS" /> 
    </xs:sequence>
</xs:complexType>
<xs:element name="ArrayOfSMS" nillable="true" type="tns:ArrayOfSMS" /> 
<xs:complexType name="SMS">
    <xs:sequence>
        <xs:element name="ID" type="xs:int" /> 
        <xs:element name="Message" nillable="true" type="xs:string" /> 
        <xs:element name="PhoneNumber" nillable="true" type="xs:string" /> 
    </xs:sequence>
</xs:complexType>
<xs:element name="SMS" nillable="true" type="tns:SMS" /> 

计数器:

<xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns="http://SendSMS.counterSchema" targetNamespace="http://SendSMS.counterSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element default="0" name="counter" type="xs:int" /> 

目标架构

为了您的理智,我不会放整个架构,它是从 WCF 服务自动生成的

Recipients 是我想从 phonenumber 字符串创建的字符串数组,因为我每条消息只有一个收件人

...
<xml>
    <complexType name="ArrayOf_soapenc_string">
        <complexContent mixed="false">
            <restriction xmlns:q1="http://schemas.xmlsoap.org/soap/encoding/" base="q1:Array">
                <attribute xmlns:d5p1="http://schemas.xmlsoap.org/wsdl/" d5p1:arrayType="q1:string[]" ref="q1:arrayType" /> 
            </restriction>
        </complexContent>
    </complexType>
    <complexType name="Submission" abstract="true">
        <sequence>
            <element xmlns:q2="http://mobicomp.com/smsexpress/webservice/server/message" name="contactLists" nillable="true" type="q2:ArrayOf_soapenc_string" /> 
            <element name="deliveryDate" nillable="true" type="dateTime" /> 
            <element name="notification" type="boolean" /> 
            <element xmlns:q3="http://schemas.xmlsoap.org/soap/encoding/" name="notificationRecipient" nillable="true" type="q3:string" /> 
            <element xmlns:q4="http://schemas.xmlsoap.org/soap/encoding/" name="notificationType" nillable="true" type="q4:string" /> 
            <element xmlns:q5="http://mobicomp.com/smsexpress/webservice/server/message" name="recipients" nillable="true" type="q5:ArrayOf_soapenc_string" /> 
            <element xmlns:q6="http://schemas.xmlsoap.org/soap/encoding/" name="sender" nillable="true" type="q6:string" /> 
            <element name="validity" type="int" /> 
        </sequence>
    </complexType>
</xml>
...

已解决:

我使用内联 XSLT 模板编写 functoid

<xsl:template name="recipients">
<xsl:param name="phone" />

<recipients>
    <recipient><xsl:value-of select="$phone" /></recipient>
</recipients>

【问题讨论】:

  • 您也可以发布架构吗?特别是目标架构。
  • 你不能只将一个字符串映射到目标元素吗?

标签: mapping biztalk biztalk-2009


【解决方案1】:

我建议您考虑对通过您的方法提取的单个字符串值使用 XSLT 模板。

因此,您创建数组并为每个字符串生成目标 Xml。

看看This Link,它谈到了在您的地图中使用 XSLT 模板。

如果没有目标架构,我目前只能建议这些。 高温

【讨论】:

  • 我知道我可以制作一个 XSLT,它会从 66666 创建一个 66666‌​s>
  • 你如何代表多个
  • 这不会发生,我为每个收件人发送一条消息,1-1 关系,模式是从一​​条消息为多个收件人准备的,1-N,但我的是个性化的
  • 啊,我明白了!我仍然建议使用 XSLT 模板将您的源代码按摩到目标表单中。如果生成目标实例来获取结构,则可以使用来自源和 XSLT 的输入重新创建它。这就是我要走的路......
【解决方案2】:

好吧,根据您实际应该发送到目的地地图的内容,我可能会这样做:

假设您收到一个字符串 flibberdyjibit 并希望使其成为 string[] 中的唯一项目,我会这样做:

public string[] ReturnStringArray(string input)
{
    string[] output = new string[] { input };
    return output;
}

如果您收到某种分隔字符串,需要将其转换为数组(我将假设为 Pipes),您会执行以下操作:

public string[] ReturnStringArray(string input)
{
    return input.split('|');
}

注意:我还没有编译任何一个,可能存在语法错误,但如果有的话,intellisense 应该可以帮助你。

【讨论】:

  • 谢谢,但结果是一样的:System.String[] 而不是字符串数组本身
  • 根据您更新的评论,您是否应该用某种子节点的数组填充父节点?所以&lt;recipients&gt;&lt;recipient&gt;Jones&lt;/recipient&gt;&lt;recipient&gt;Smith&lt;/recipient&gt;&lt;/recipients&gt;?
  • 是的。我有一个字符串“+33344434”,它必须是: +3344434 但我只能得到 +3344434
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-21
  • 1970-01-01
  • 1970-01-01
  • 2021-11-15
  • 1970-01-01
相关资源
最近更新 更多