Access 3rd web services from c++ MFC

Hi,

I need to access our developed web services from PW explorer.

I took example project from SDK library -  docprop. I would like to have a possibility have a button which connect to my web services and get some information from there.

In C# i use code like this, but can't find how to make run it on C++ with MFC.

The other option is create command in C# for PW explorer, but i do not know how to this as well.

Thanks

Darius

using (var client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }))
{
client.BaseAddress = new Uri(sDomain);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(scheme, pass);
String sApiPath = "/master-tables";
HttpResponseMessage response = client.GetAsync(sApiPath).Result;
response.EnsureSuccessStatusCode();
string result = response.Content.ReadAsStringAsync().Result;
List<MasterTable> prTables = JsonConvert.DeserializeObject<List<MasterTable>>(result);

foreach (MasterTable t in prTables)
{
if (t.name.Contains(tablename) == true)
{
String sApiPathTr = "/master-tables/" + t.masterTableId + "/records";
HttpResponseMessage responseTr = client.GetAsync(sApiPathTr).Result;
responseTr.EnsureSuccessStatusCode();
string resultTr = responseTr.Content.ReadAsStringAsync().Result;
ReadMasterTableFromCodes = JsonConvert.DeserializeObject<List<TableRecord>>(resultTr);
break;
}
}
}

  • I think you probably have to define your static method as public, but the problem reported appears to be in your post build commands.  Perhaps using 'move' is the problem?  FWIW, I always copy the modified DLL file, typically with something like this:

    echo "Executing DllExporterNet4.exe $(TargetFileName)..."
    DllExporterNet4.exe $(TargetFileName)
    
    echo "copy $(TargetName).Exports$(TargetExt) $(TargetFileName)..."
    copy $(TargetName).Exports$(TargetExt) $(TargetFileName)
    
    echo "copy $(TargetFileName) "$(PWBIN)"..."
    copy $(TargetFileName) "$(PWBIN)"

    Now depending upon how you have coded all of this, you might have to load your DLL yourself before attempting to call your exported function.

    Also, you should be using the x86 version of DllExporterNet4 since this is for ProjectWise Explorer, which is an x86 application.

  • Here's some sample c# code that you can call from a .mrr file.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Diagnostics;
    using System.Data;
    using DllExporterNet4;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    
    namespace ManagedCodeCalledFromMrr
    {
        public class MyManagedCode
        {
            [DllExport]
            public static int MyDocCmdInManagedCode
            (
                uint uiCount, //==>Count of documents 
                [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)]int[] plProjArray, //==>Project number Array
                [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)]int[] plDocArray //==> Document number Array
            )
            {
                string msg = string.Empty;
    
                // Select first document's properties
                long retValue = PWWrapper.aaApi_SelectDocument(plProjArray[0], plDocArray[0]);
                if (retValue == 1)  // document exists
                {
                    String DocName = PWWrapper.aaApi_GetDocumentStringProperty(PWWrapper.DocumentProperty.Name, 0);
                    msg = string.Format("Selected Document Count is {0}", uiCount) +
                        string.Format("\nFirst Document name is '{0}'", DocName);
    
                }
                else if (retValue == -1)    // error
                {
                    msg = string.Format("[{0}]\n{1}\n{2}",
                        PWWrapper.aaApi_GetLastErrorDetail(),
                        PWWrapper.aaApi_GetLastErrorMessage(),
                        PWWrapper.aaApi_GetLastErrorDetail());
                }
                else  // document does not exist
                {
                    msg = string.Format("Document does not exist!");
                }
    
                MessageBox.Show(msg, "ManagedCodeCalledFromMrr", MessageBoxButtons.OK);
    
                return 0;
            }
        }
    }
    
    

    Here's how I used DllExporterNet4 in a post build step:

    echo "Executing DllExporterNet4.exe $(TargetFileName)..."
    DllExporterNet4.exe $(TargetFileName)
    
    echo copying $(TargetName).Exports$(TargetExt) to $(TargetFileName)...
    copy $(TargetName).Exports$(TargetExt) $(TargetFileName)
    
    echo copying x$(TargetFileName) to $(PWBinx86Dir)...
    copy $(TargetFileName) "$(PWBinx86Dir)"
    
    echo Copying $(SolutionDir)Menus\*.mrr  to "$(PWBinx86Dir)"...
    Copy "$(SolutionDir)Menus\*.mrr " "$(PWBinx86Dir)"

    And here's a PowerShell script to create the macros that I use (primarily with C++ projects):

    [Environment]::SetEnvironmentVariable("PWBinx86Dir", "C:\Program Files (x86)\Bentley\ProjectWise\bin\", "Machine")
    [Environment]::SetEnvironmentVariable("PWIncludeX86Dir", "C:\Program Files\Bentley\ProjectWise\SDK\include\", "Machine")
    [Environment]::SetEnvironmentVariable("PWLibx86Dir", "C:\Program Files\Bentley\ProjectWise\SDK\lib\Win32\", "Machine")
    [Environment]::SetEnvironmentVariable("PWRsrcx86Dir", "C:\Program Files (x86)\Bentley\ProjectWise\rsrc\", "Machine")
    [Environment]::SetEnvironmentVariable("PWSDKx86Dir", "C:\Program Files\Bentley\ProjectWise\SDK\", "Machine")
    
    [Environment]::SetEnvironmentVariable("PWBinx64Dir", "C:\Program Files\Bentley\ProjectWise\bin\", "Machine")
    [Environment]::SetEnvironmentVariable("PWIncludeX64Dir", "C:\Program Files\Bentley\ProjectWise\SDK\include\", "Machine")
    [Environment]::SetEnvironmentVariable("PWLibx64Dir", "C:\Program Files\Bentley\ProjectWise\SDK\lib\x64\", "Machine")
    [Environment]::SetEnvironmentVariable("PWRsrcx64Dir", "C:\Program Files\Bentley\ProjectWise\rsrc\", "Machine")
    [Environment]::SetEnvironmentVariable("PWSDKx64Dir", "C:\Program Files\Bentley\ProjectWise\SDK\", "Machine")
    
    [Environment]::SetEnvironmentVariable("PythonDir", "C:\DevTools\Python27", "Machine")
    

    I posted these at this link: https://communities.bentley.com/products/programming/projectwise_programming/m/mediagallery/273951 

    Answer Verified By: Darius Simkunas