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;
}
}
}

Parents
  • If I understand your question, you could create a C# Class Library (DLL) that calls your web service, but then make it available to unmanaged (C++) code.  Take a look at Dave Brumbaugh solution to how to do this at https://www.nuget.org/packages/DllExporterNet4X64/  or this one https://www.nuget.org/packages/DllExporterNet4/ .

    You might also want to take a look at Dave's Classes to access the ProjectWise APIs from C# at https://github.com/DaveBrumbaugh/MostOfDavesClasses-CSharp-Wrappers-For-ProjectWise 

  • Hi Dan,

    Thank you for quick answer and links.

    My target is to have the same code in C++, what I have in c#.

    I do not know is there in c++ MFC some functions which allows me get the same result what I have in C#.

    I use MostOfDave clases in my C# projects and in really useful. 

    The question there is it possible create Menu in PW explorer using C# and MostOfDaveClases?

    Best regards

    Darius

  • Darius,

    I don't know if there are MFC tools available to do what you want to do, but I suspect that you can do all that you want to do with C++, but you will have to do some "research" into the means to do so.

    If you already have working C# code, and are more comfortable using C# and .NET, then there isn't really anything from stopping you to use both, you just need to have a way to invoke the C# code from PW Explorer, which of course is unmanaged code.  Using the DllExporterNet4 tool makes this relatively easy to do.

    If you want to call your C# code from a PW menu, trying this approach:

    • Use the Menu Editor to create an MRR file that specifies C++ coded functions
    • Have your C++ menu functions call your C# code exported with the DllExporterNet4 tool

    I have personally used this approach and the advantage is that you can keep the C++ code pretty minimal while taking advantage of the C#.NET development environment to implement whatever it is that you already know how to make work.

    HTHs 

  • Hi,

    Thank you for pointing me to the right direction, appreciate it.

    Sorry, but I do not understand what I do wrong.

    I have done simple C# dll and try follow by instruction.

    Installed 

    Install-Package DllExporterNet4X64 -Version 1.0.0

    There is my C# code.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace Exportteddll
    {
    public class ExportedDll
    {

    [DllExporterNet4X64.DllExport]
    static void test ( )
    {
    System.Windows.Forms.MessageBox.Show("Hello");
    }
    }

    On post build I have added.

    DllExporterNet4X64.exe $(TargetFileName)
    move $(TargetName).Exports$(TargetExt) $(TargetFileName)

    on build I has got error message.

    Severity Code Description Project File Line Suppression State
    Error The command "DllExporterNet4X64.exe Exportteddll.dll
    move Exportteddll.Exports.dll Exportteddll.dll" exited with code 1. ExportedDll

    Best regards

    Darius

Reply
  • Hi,

    Thank you for pointing me to the right direction, appreciate it.

    Sorry, but I do not understand what I do wrong.

    I have done simple C# dll and try follow by instruction.

    Installed 

    Install-Package DllExporterNet4X64 -Version 1.0.0

    There is my C# code.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace Exportteddll
    {
    public class ExportedDll
    {

    [DllExporterNet4X64.DllExport]
    static void test ( )
    {
    System.Windows.Forms.MessageBox.Show("Hello");
    }
    }

    On post build I have added.

    DllExporterNet4X64.exe $(TargetFileName)
    move $(TargetName).Exports$(TargetExt) $(TargetFileName)

    on build I has got error message.

    Severity Code Description Project File Line Suppression State
    Error The command "DllExporterNet4X64.exe Exportteddll.dll
    move Exportteddll.Exports.dll Exportteddll.dll" exited with code 1. ExportedDll

    Best regards

    Darius

Children
No Data