在Azure逻辑应用程序中转换XML,将C#程序集(.DLL)文件上载到Azure集成帐户,并在XSLT(映射)中使用它

在Azure逻辑应用程序中转换XML,将C#程序集(.DLL)文件上载到Azure集成帐户,并在XSLT(映射)中使用它,c#,azure,xslt,assemblies,azure-logic-apps,C#,Azure,Xslt,Assemblies,Azure Logic Apps,在日志应用程序中,我有一个Source.xml文件,需要使用XSLT将其转换为另一个destination.xml。 在XSLT中,我需要使用C#代码实现一些自定义逻辑,这些代码将上载到Azure集成帐户“组装部分” 我已经用StrongName创建了一个C#assembly文件,但需要了解如何从XSLT调用C#assembly方法 如果有人能用一个非常基本的示例共享一个工作示例代码,我将不胜感激。问题是关于如何将c#assembly与XSLT结合使用。 XSLT和C#都放在Azure集成帐户中

在日志应用程序中,我有一个Source.xml文件,需要使用XSLT将其转换为另一个destination.xml。 在XSLT中,我需要使用C#代码实现一些自定义逻辑,这些代码将上载到Azure集成帐户“组装部分”

我已经用StrongName创建了一个C#assembly文件,但需要了解如何从XSLT调用C#assembly方法


如果有人能用一个非常基本的示例共享一个工作示例代码,我将不胜感激。

问题是关于如何将c#assembly与XSLT结合使用。
XSLT和C#都放在Azure集成帐户中,即分别放在映射和汇编工件部分

我找到了一个示例供您参考:

c代码显示如下:

using System;
namespace ExtAssembly
{
 public static class CalcFunctions
 {
 public static Int64 Add(Int64 a, Int64 b)
 {
 return a + b;
 }
 public static Int64 Subtract(Int64 a, Int64 b)
 {
 return a - b;
 }
 public static Int64 Multiply(Int64 a, Int64 b)
 {
 return a * b;
 }
 public static Double Divide(Int64 a, Int64 b)
 {
 return a / b;
 }
 }
}
<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform Jump " xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl userCSharp" version="1.0" xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp Jump ">
 <xsl:output omit-xml-declaration="yes" media-type="application/text" method="text" version="1.0" />
 <xsl:param name="MethodName" />
 <xsl:param name="Parameters" />
 <xsl:template match="/">
 <xsl:value-of select ="userCSharp:Invoke($MethodName, substring-before(substring-after($Parameters, '('), ')'))" />
 </xsl:template>
 <msxsl:script language="C#" implements-prefix="userCSharp"> 
 <msxsl:assembly name="ExtAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx" />
 <msxsl:using namespace="System.Reflection" />
 <msxsl:using namespace="System.Text.RegularExpressions" />
 <msxsl:using namespace="ExtAssembly" />
 <![CDATA[
 public object Invoke(string methodName, string methodParameters)
 {
 MatchCollection matches = new Regex("((?<=\")[^\"]*(?=\"(,|$)+)|(?<=,|^)[^,\"]*(?=,|$))").Matches(methodParameters); 
 ParameterInfo[] pars = typeof(CalcFunctions).GetMethod(methodName).GetParameters();
 object[] methodPars = new object[pars.Length]; 
 for (int i = 0; i < pars.Length; i++)
 {
 methodPars[i] = Convert.ChangeType(matches[i].Value, pars[i].ParameterType);
 }
 return typeof(CalcFunctions).GetMethod(methodName).Invoke(null, methodPars);
 }
 ]]>
</msxsl:script>
</xsl:stylesheet>
我们可以在xslt中使用c#代码,如下所示:

using System;
namespace ExtAssembly
{
 public static class CalcFunctions
 {
 public static Int64 Add(Int64 a, Int64 b)
 {
 return a + b;
 }
 public static Int64 Subtract(Int64 a, Int64 b)
 {
 return a - b;
 }
 public static Int64 Multiply(Int64 a, Int64 b)
 {
 return a * b;
 }
 public static Double Divide(Int64 a, Int64 b)
 {
 return a / b;
 }
 }
}
<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform Jump " xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl userCSharp" version="1.0" xmlns:userCSharp="http://schemas.microsoft.com/BizTalk/2003/userCSharp Jump ">
 <xsl:output omit-xml-declaration="yes" media-type="application/text" method="text" version="1.0" />
 <xsl:param name="MethodName" />
 <xsl:param name="Parameters" />
 <xsl:template match="/">
 <xsl:value-of select ="userCSharp:Invoke($MethodName, substring-before(substring-after($Parameters, '('), ')'))" />
 </xsl:template>
 <msxsl:script language="C#" implements-prefix="userCSharp"> 
 <msxsl:assembly name="ExtAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxx" />
 <msxsl:using namespace="System.Reflection" />
 <msxsl:using namespace="System.Text.RegularExpressions" />
 <msxsl:using namespace="ExtAssembly" />
 <![CDATA[
 public object Invoke(string methodName, string methodParameters)
 {
 MatchCollection matches = new Regex("((?<=\")[^\"]*(?=\"(,|$)+)|(?<=,|^)[^,\"]*(?=,|$))").Matches(methodParameters); 
 ParameterInfo[] pars = typeof(CalcFunctions).GetMethod(methodName).GetParameters();
 object[] methodPars = new object[pars.Length]; 
 for (int i = 0; i < pars.Length; i++)
 {
 methodPars[i] = Convert.ChangeType(matches[i].Value, pars[i].ParameterType);
 }
 return typeof(CalcFunctions).GetMethod(methodName).Invoke(null, methodPars);
 }
 ]]>
</msxsl:script>
</xsl:stylesheet>

之后,我们可以在逻辑应用程序中调用它(在“TransformXML”操作中使用“MethodName”和“Parameters”提供它)

有关更多信息,请参阅此

希望对你的问题有所帮助