tags:

views:

671

answers:

4

Wondering if anybody out there has any success in using the JDEdwards XMLInterop functionality. I've been using it for a while (with a simple PInvoke, will post code later). I'm looking to see if there's a better and/or more robust way.

Thanks.

+2  A: 

As promised, here is the code for integrating with JDEdewards using XML. It's a webservice, but could be used as you see fit.

namespace YourNameSpace

{

/// <summary>
/// This webservice allows you to submit JDE XML CallObject requests via a c# webservice
/// </summary>
[WebService(Namespace = "http://WebSite.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class JdeBFService : System.Web.Services.WebService
{
    private string _strServerName;
    private UInt16 _intServerPort;
    private Int16 _intServerTimeout;

    public JdeBFService()
    {
        // Load JDE ServerName, Port, & Connection Timeout from the Web.config file.
        _strServerName = ConfigurationManager.AppSettings["JdeServerName"];
        _intServerPort = Convert.ToUInt16(ConfigurationManager.AppSettings["JdePort"], CultureInfo.InvariantCulture);
        _intServerTimeout = Convert.ToInt16(ConfigurationManager.AppSettings["JdeTimeout"], CultureInfo.InvariantCulture);

    }

    /// <summary>
    /// This webmethod allows you to submit an XML formatted jdeRequest document
    /// that will call any Master Business Function referenced in the XML document
    /// and return a response.
    /// </summary>
    /// <param name="Xml"> The jdeRequest XML document </param>
    [WebMethod]
    public XmlDocument JdeXmlRequest(XmlDocument xmlInput)
    {
        try
        {
            string outputXml = string.Empty;
            outputXml = NativeMethods.JdeXmlRequest(xmlInput, _strServerName, _intServerPort, _intServerTimeout);

            XmlDocument outputXmlDoc = new XmlDocument();
            outputXmlDoc.LoadXml(outputXml);
            return outputXmlDoc;
        }
        catch (Exception ex)
        {
            ErrorReporting.SendEmail(ex);
            throw;
        }
    }
}

/// <summary>
/// This interop class uses pinvoke to call the JDE C++ dll.  It only has one static function.
/// </summary>
/// <remarks>
/// This class calls the xmlinterop.dll which can be found in the B9/system/bin32 directory.  
/// Copy the dll to the webservice project's /bin directory before running the project.
/// </remarks>
internal static class NativeMethods
{
    [DllImport("xmlinterop.dll",
        EntryPoint = "_jdeXMLRequest@20",
        CharSet = CharSet.Auto,
        ExactSpelling = false,
        CallingConvention = CallingConvention.StdCall,
        SetLastError = true)]
    private static extern IntPtr jdeXMLRequest([MarshalAs(UnmanagedType.LPWStr)] StringBuilder server, UInt16 port, Int32 timeout, [MarshalAs(UnmanagedType.LPStr)] StringBuilder buf, Int32 length);

    public static string JdeXmlRequest(XmlDocument xmlInput, string strServerName, UInt16 intPort, Int32 intTimeout)
    {
        StringBuilder sbServerName = new StringBuilder(strServerName);
        StringBuilder sbXML = new StringBuilder();
        XmlWriter xWriter = XmlWriter.Create(sbXML);
        xmlInput.WriteTo(xWriter);
        xWriter.Close();

        string result = Marshal.PtrToStringAnsi(jdeXMLRequest(sbServerName, intPort, intTimeout, sbXML, sbXML.Length));

        return result;
    }
}

}

You have to send it messages like the following one:

<jdeRequest type='callmethod' user='USER' pwd='PWD' environment='ENV'>
  <callMethod name='GetEffectiveAddress' app='JdeWebRequest' runOnError='no'>
    <params>
      <param name='mnAddressNumber'>10000</param>
    </params>
  </callMethod>
</jdeRequest>
Jon Dewees
A: 

Hi, Could you please provide the Source Code? I have tried different ways to be able to call the xmlInterop.dll but none have succeeded. I keep getting BadImageFormatException. I suspect that the DLL cant be found.

Deepak, I can't provide more source that what's listed above, as it would violate an agreement I have with the owners of the code. However I can tell you that you need the full JDE client installed for this to work. Furthermore, this is running on JDE 8.something, so if you're using a different version I can't guarantee it will work.
Jon Dewees
You don't need the full JDE fat client installed - you can get away with copying a subset of the dlls to the target machine. Eg with the 8.97 tools, you need icudt32.dll, icudt32l.dat, icui18n.dll, icuuc.dll, jdel.dll, jdeunicode.dll, PSThread.dll, ustdio.dll and xmlinterop.dll. Use SetDllDirectory() or add the location to PATH. You may also need to set the environment variable JDE_B9_ICU_DATA.
Sam
A: 

I changed our JDE web service to use XML Interop after seeing this code, and we haven't had any stability problems since. Previously we were using the COM Connector, which exhibited regular communication failures (possibly a connection pooling issue?) and was a pain to install and configure correctly.

We did have issues when we attempted to use transactions, but if you're doing simple single business function calls this shouldn't be an problem.

Update: To elaborate on the transaction issues - if you're attempting to keep a transaction alive over multiple calls, AND the JDE application server is handling a modest number of concurrent calls, the xmlinterop calls start returning an 'XML response failed' message and the DB transaction is left open with no way to commit or rollback. It's possible tweaking the number of kernels might solve this, but personally, I'd always try to complete the transaction in a single call.

Sam
Thanks, that's great additional info Sam!
Jon Dewees
A: 

Hello Sam,

I am looking for a similar solution where we have to invoke JDE business function from .NETprogram(web service) using XML Interoperability connector. Can you let me know how to accomplish this step by step wise or send me any document(s) if you have which can help me to complete this task. my email id : [email protected]

Thanks in advance, Vijay.