Want to call a Web Service from a C++/MFC App in VS.NET 2003

I need to connect to a Web Service from a C++/MFC app.  I created a Web 
Reference to my Web Service on localhost.  There was a localhost.h created 
and in there was my class defined as a template as follows;

template <typename TClient = CSoapSocketClientT<> >
class CRegistrationInfoT :
    public TClient,
    public CSoapRootHandler
{
    ...
}

In this class is a definition of the routines that I want to call, one of 
which is defined as:

    HRESULT GetClasses(
        ClassInfo** GetClassesResult, int* GetClassesResult_nSizeIs
    );

I can't figure out how to instantiate an instance of the CRegistrationInfo 
class with the template.  Is there any documentation on this or a simple 
walk-through.  All I've been able to find so far is references to a COM 
interface to .NET C# or a managed environment which seems overly difficult 
to implement.  The creation of the Web Reference was easy.  All I need is 
some hint as to how to instantiate the class within my MFC project.

Ed
--
Edward E.L. Mitchell
Web: www.racesail.org
Phone: (239)415-7039
6707 Daniel Court
Fort Myers, FL 33908 


0
3/18/2005 3:24:56 AM
vc.mfc 33608 articles. 0 followers. Follow

6 Replies
515 Views

Similar Articles

[PageSpeed] 35

Hi Edward,

>I can't figure out how to instantiate an instance of the CRegistrationInfo 
>class with the template.  Is there any documentation on this or a simple 
>walk-through.

I am not very clear about your CRegistrationInfo class, is it a pure C++ 
templete class or any thing else?
And what's your detail problem on instantiating it, the general _new_ 
couldn't make it? 

By the way, how about the GetClasses function, is it a simple class method 
or a COM method call?


Thanks!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ��C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn 

This posting is provided "AS IS" with no warranties, and confers no rights.

0
v-garych (605)
3/18/2005 10:15:11 AM
Gary,

The CRegistrationClass was created by the Visual Studio Wizard.  I created a 
test MFC project and then selected Add Web Reference.  A WebService.h file 
was created that contained a localhost.h file with the meat of the interface 
contained therein.  There are over a thousand lines in localhost.h that the 
Wizard produced!

My Web Service has a HelloWorld() function that was created by the .NET 
Wizard (it's a C# program) along with my stuff.  Inside localhost.h is the 
template definition for the Web Service CRegistrationInfoT class (this name 
was conjured up by the Wizard) that starts off with:


template <typename TClient = CSoapSocketClientT<> >
class CRegistrationInfoT :
    public TClient,
    public CSoapRootHandler
{
protected:

    const _soapmap ** GetFunctionMap();
    const _soapmap ** GetHeaderMap();
    void * GetHeaderValue();
    const wchar_t * GetNamespaceUri();
    const char * GetServiceName();
    const char * GetNamespaceUriA();
    ...
    HRESULT HelloWorld(
        BSTR* HelloWorldResult
    );
    HRESULT GetClasses(
        ClassInfo** GetClassesResult, int* GetClassesResult_nSizeIs
    );
    ...
    ... for 1000 lines
    ...
};

As you can see the GetClasses(...) method is defined to return an HRESULT. 
I presume that this makes a COM method call.  The Web Service is defined to 
return an array of CClassInfo classes.  In the C# Web Service definition, 
it's defined as:

 [WebMethod(Description="Returns an array of class info objects")]
    public ClassInfo[] GetClasses()
    {
    ...
    }

After the VS Wizard had generated the localhost.h code for my Web Reference, 
I tried to use it by putting the following in the main app .cpp constructor:

CAccessRegInfoApp::CAccessRegInfoApp()
{
    CRegistrationInfoT ri;
    BSTR HelloWorldResult[1000];
    HRESULT hr = ri.HelloWorld(&HelloWorldResult);
}

just to see if I can get "HelloWorld" back.

When I compile this I see the following error messages:

AccessRegInfo.cpp(51) : error C2955: 'RegistrationInfo::CRegistrationInfoT' 
: use of class template requires template argument list
AccessRegInfo\localhost.h(135) : see declaration of 
'RegistrationInfo::CRegistrationInfoT'
AccessRegInfo.cpp(51) : error C2133: 'ri' : unknown size
AccessRegInfo.cpp(51) : error C2512: 'RegistrationInfo::CRegistrationInfoT' 
: no appropriate default constructor available
AccessRegInfo.cpp(51) : error C2262: 'ri' : cannot be destroyed
AccessRegInfo\AccessRegInfo.cpp(53) : fatal error C1903: unable to recover 
from previous error(s); stopping compilation

How can I instantiate the template class that was created?

Is there any documentation on the 1000+ lines that was created in 
localhost.h by the Wizard?

Regards,


Ed




"Gary Chang[MSFT]" <v-garych@online.microsoft.com> wrote in message 
news:SCEOpN6KFHA.1376@TK2MSFTNGXA02.phx.gbl...
> Hi Edward,
>
>>I can't figure out how to instantiate an instance of the CRegistrationInfo
>>class with the template.  Is there any documentation on this or a simple
>>walk-through.
>
> I am not very clear about your CRegistrationInfo class, is it a pure C++
> templete class or any thing else?
> And what's your detail problem on instantiating it, the general _new_
> couldn't make it?
>
> By the way, how about the GetClasses function, is it a simple class method
> or a COM method call?
>
>
> Thanks!
>
> Best regards,
>
> Gary Chang
> Microsoft Community Support
> --------------------
> Get Secure! ��C www.microsoft.com/security
> Register to Access MSDN Managed Newsgroups!
> http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
> &SD=msdn
>
> This posting is provided "AS IS" with no warranties, and confers no 
> rights.
> 


0
3/18/2005 3:39:34 PM
Hi Richard,

Is the name of your  web service is the RegistrationClass?

If so, the CRegistrationClassT(could be typedef as CRegistrationClass) 
would be the client C++ wrapped class of your web service, and you can 
instantiate it though its namespace, and then call your web service's 
method via the instance: 

//assume the name of your web service is RegistrationClass
RegistrationClass::CRegistrationClass *s = new 
RegistrationClass::CRegistrationClass();
...

The MSDN has a walk through doc about how to consume a web service in a 
rich client MFC application:
Walkthrough: Creating a Rich Client Application with MFC/Creating and 
Consuming an Existing XML Web Service
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/ht
ml/vblrfWalkthroughCreatingRichClientApplicationWithMFC.asp

 
Wish it helps!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ��C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn 

This posting is provided "AS IS" with no warranties, and confers no rights.

0
v-garych (605)
3/19/2005 5:31:08 AM
I have the same problem

How to consume web service write in c# without info about size of 
returns arrays ? Web service returns arrayList of string - in my mfc 
client in proxy class I get somethig like this:

struct ArrayOfAnyType
{
	BSTR anyType;
};

Web method as "out" parameter needs pointer to that struct.
So I delclare ArrayOfAnyType *Out but i get access violation error and
when i try for example:

ArrayOfAnyType *In = new ... [10] then i get empty array.

How to eat that ?

Best regards
Piter

Gary Chang[MSFT] wrote:
> Hi Richard,
> 
> Is the name of your  web service is the RegistrationClass?
> 
> If so, the CRegistrationClassT(could be typedef as CRegistrationClass) 
> would be the client C++ wrapped class of your web service, and you can 
> instantiate it though its namespace, and then call your web service's 
> method via the instance: 
> 
> //assume the name of your web service is RegistrationClass
> RegistrationClass::CRegistrationClass *s = new 
> RegistrationClass::CRegistrationClass();
> ..
> 
> The MSDN has a walk through doc about how to consume a web service in a 
> rich client MFC application:
> Walkthrough: Creating a Rich Client Application with MFC/Creating and 
> Consuming an Existing XML Web Service
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/ht
> ml/vblrfWalkthroughCreatingRichClientApplicationWithMFC.asp
> 
>  
> Wish it helps!
> 
> Best regards,
> 
> Gary Chang
> Microsoft Community Support
> --------------------
> Get Secure! ��C www.microsoft.com/security
> Register to Access MSDN Managed Newsgroups!
> http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
> &SD=msdn 
> 
> This posting is provided "AS IS" with no warranties, and confers no rights.
> 
0
3/24/2005 11:21:13 AM
Gary,

I followed the walkthrough and was able to create and use the web service. 
I finished up putting the following member in a separate class:

    CRegistrationInfoT<CSoapSocketClientT<> >* m_pRegInfo;

and then created an instance when the class was created via:

    m_pRegInfo = new CRegistrationInfoT<CSoapSocketClientT<> >();

and then I could invoke the "HelloWorld" function via:

    BSTR HelloWorldResult[1000];
    HRESULT hr = m_pRegInfo->HelloWorld(HelloWorldResult);

I'm not quite sure why I was getting the previous error but the web service 
works now!

Thanks for the feedback.

Ed


"Gary Chang[MSFT]" <v-garych@online.microsoft.com> wrote in message 
news:D0CGkTELFHA.1528@TK2MSFTNGXA02.phx.gbl...
> Hi Richard,
>
> Is the name of your  web service is the RegistrationClass?
>
> If so, the CRegistrationClassT(could be typedef as CRegistrationClass)
> would be the client C++ wrapped class of your web service, and you can
> instantiate it though its namespace, and then call your web service's
> method via the instance:
>
> //assume the name of your web service is RegistrationClass
> RegistrationClass::CRegistrationClass *s = new
> RegistrationClass::CRegistrationClass();
> ..
>
> The MSDN has a walk through doc about how to consume a web service in a
> rich client MFC application:
> Walkthrough: Creating a Rich Client Application with MFC/Creating and
> Consuming an Existing XML Web Service
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/ht
> ml/vblrfWalkthroughCreatingRichClientApplicationWithMFC.asp
>
>
> Wish it helps!
>
> Best regards,
>
> Gary Chang
> Microsoft Community Support
> --------------------
> Get Secure! ��C www.microsoft.com/security
> Register to Access MSDN Managed Newsgroups!
> http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
> &SD=msdn
>
> This posting is provided "AS IS" with no warranties, and confers no 
> rights.
> 


0
5/26/2005 2:13:21 AM
It's great, Ed, I am glad to see it works now:)

Good Luck!

Best regards,

Gary Chang
Microsoft Community Support
--------------------
Get Secure! ��C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
&SD=msdn 

This posting is provided "AS IS" with no warranties, and confers no rights.

0
v-garych (605)
5/26/2005 6:07:16 AM
Reply:

Similar Artilces:

Intercept ShutDown Event in C# ? Problem with error code 0xC000014
Hi all, I am trying to write application which will intercept ShutDown event and then cancel that even do some backup work and then fire again shut down event. The problem I am facing is that after capturing shutdown event following line does not help me to cancel it completlly: System.Diagnostics.Process.Start(@"C:\WINNT\system32\shutdown.exe", "-a"); So ShutDown seems to be canceld but my application report error code 0xC0000142 in User32.dll, and can not proceed with backup operation. Is there any way to cancel shutdown event and that application have a...

Why do I get web favorites as well as directories?
I can't find an answer to this, maybe it's so obvious it's never been needed to be discussed...? When I use the file open dialogue box in Excel and click on 'Favorites', as well as my favorite directories I get a list of my favorite internet sites as well. This is really annoying me, is there a way to only show directories? ...

outlook 2003 custom form no RTF
I was using Outlook 2002 sp3 till now. Used to create custom forms, publish it (with the option, save form defination with item as 'NO') in the personal forms library. Send the custom form to myself, and when I receive it, it used to be in rich text format(RTF) and wud display the custom form as it is. But now, in the same machine, am using outlook 2003,and suddenly, the RTF, is not being displayed. Instead, the inbox has html file, so I can view the custom form.. Pls help.. Thanks in advance What's the value of the MessageClass property for the item you received? = Has your m...

IMS service could not start
As part the plan of migrating Exchange 5.5 to Exchange 2003, I am recovering the Exchange 5.5 sp4 into the lab, which is in a Windows 2000 server on an Windows 2003 domain. The DS and IS restoration is good, the internal email is working, all the other services are running, except the IMS service could not start. Therefore there is no communication with the external world. When I manual start the IMS service, the error message is: Could not start the Microsoft Exchange Internet Mail Service service on local computer, the service did not return an error. This could be an internal windows erro...

Could NOT change mail address after windows server 2003 sp1
Exchange Server 20003 SP1 on Server 2003 Enterprise After upgrade to Win Server 2003 SP1 only users who are members of Local Administrators Group (in Exchange 2003 server) can change an email address. They can create new mail enabled users (with default addresses) The error message is An Exchange Server could not be found in the domain Check if the Microsoft System Attendant service is running on the Exchange Server ID no: c10308a2 Microsoft Active Directory - Exchange Extension What errors do you see in the event logs (specifically the application log and system log). That sounds rea...

Console app with no console window
I'm trying to replace our fairly crappy scheduler with the NT Task Scheduler to run a console app. When our scheduler runs this app, it does so with no console window and the app then closes its standard in/out handles. Our scheduler calls CreateProcess() and sets the flag parameter to DETACHED_PROCESS. The command line for the console app includes a /d switch to tell it to close its IO handles. How would I get the same behaviour when running the console app from the NT Task Scheduler? I've looked at the interface for the task object and can't see anything there that would stop t...

adding gmail account in outlook on SBS 2003 R2
I'm running a SBS 2003 R2 and currently have each networked PC setup with an exchange email account. I have stopped using the exchange email accounts and would like to setup a (IMAP) Gmail account and I was able to setup the account through (outlook 2003) tools, account settings and adding a new account on a laptop that was not networked but when I try this on the networked PCs it does not work. I’m going to try to change some server settings but any help would be appreciated. -- TTK In article <F512405C-D5E6-4465-AFB0-1748EA5DC6C6@microsoft.com>,=20 TTK@discuss...

YAPTQ: Mixed data types in custom groups (Excel 2003)
Hello, I'm trying to get the following accomplished in Excel 2003: I have a column in a table that keeps track of how late a form was turned in. It can have an integer (for the number of days it was late) or one of several text strings ("On time," "Cannot determine," "Outside report dates.") I need to be able to generate the totals for: On time or within 7 days late, 8-15 days, More than 15 days Cannot determine Outside report dates It seems like it should be a straightforward procedure, where one can specify a range of numbers, or a list of values, but I ...

publisher 2003 can't upload site Please Help
Greetings, I have tried to upload my 2003 publisher website for 4 hours. I know how to use ftp, I know how to use http due to the wonderful directions I found through this website. When I use FTP I get 'Publisher could not save the fiel to the Web. Check your URL or network connection'. I check them and they are fine. When I use HTTP the programs stops responding, the page goes white and this can be verified by ctrl alt delete and you can clearly see the writing not responding. After I get it shut down I get a error report. Error signature: szAppName: MSPUB.EXE szAppVer:...

file association using MFC
Hi there: I am in the process of leaning VC++ MFC. I have written a program wthat will display the complete path for the selected file name from open dialog box. Now I would like to associate my program to a file type.. lets say .jpeg files. When I double click on any .jpeg files I would like to have may program open and display the complete path. I know it has to do something with DDE. Can somebody point me to the right direction. Thanks for your help Biju Here is the code void CChildView::OnFileOpen() { static char BASED_CODE szFilter[] = "Image Files (*.jpeg, *.jpg, *....

eConnect Outgoing Services Starts then Stops
I have just installed eConnect 9 on a Windows 2003 Enterprise server. When I try to start the "Microsoft Business Solutions - Great Plains eConnect Outgoing Service 9.0" service I receive the following message: The Microsoft Business Solutions - Great Plains eConnect Outgoing Service 9.0 service on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service. What can I do to resolve this issue? Any help is appreciated. Even I'm facing the same problem but I'm using GP 8.0...

disable forwarding feature exchange 2003 in OWA
Does anyone know of a way to disable this feature in outlook web access for exchange 2003? we would like to restrict mailbox forwarding to an administrative only task. thank you team! -- nick If you did this, what would prevent the user from simply using the "Reply" function and changing the recipients address or creating a new email and pasting in the contents of the messages they want to forward? On Mon, 3 May 2004 15:44:52 -0400, "Nicholas Oneil" <nick@logicworks.net> wrote: >Does anyone know of a way to disable this feature in outlook web access for &...

Stop "attachments of message have changed...do you want to save?"
How do I stop receiving this message for any message for which I have merely opened an attachment, without making any change to it? This greatly depends on your version of Outlook and the type of attachment. For details see; http://www.msoutlook.info/question/175 -- Robert Sparnaaij [MVP-Outlook] Coauthor, Configuring Microsoft Outlook 2003 http://www.howto-outlook.com/ Outlook FAQ, HowTo, Downloads, Add-Ins and more http://www.msoutlook.info/ Real World Questions, Real World Answers ----- "DaveHause" <DaveHause@discussions.microsoft.com> wrote in messag...

Adding password protection to an MFC application
How do I add this capability to an MFC application? Basically what I need is the ability to pop-up a logon window before the application starts (After the splash window appears). And, what if I want to link this password to an Access DB file accessed by the application I created? -- hf Use a simple DoModal on InitDialog or during AppInit For access DB's, use CDaoDatabase and CDaoRecordset "hfontanez" <hfontanez@discussions.microsoft.com> wrote in message news:7A7A5BB1-BE92-4071-A3B8-69CC1AE863CE@microsoft.com... > How do I add this capability to an MFC applicatio...

Outlook 2003
Hi Am running outlook 2003 on a new Core2 duo running Vista Home Premium with all M$oft updates applied. When I receive emails that are supposed to have photos attached, I often receive them in plain text format with HTML code. The pictures are converted to a bunch of spurious characters eg; --_ab33f5dc-d792-409c-946f-7e6261a82e82_-- --_0b4657a7-168c-456f-a2b3-35bc796bdbf1_ Content-Type: image/jpeg Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="IMG_0434.JPG" /9j/4AAQSkZJRgABAAEAtAC0AAD//gAfTEVBRCBUZWNobm9sb2dpZXMgSW5jLiBWMS4wMQD/2wCE AAwICQsJCA...

How do I get rid of the box called "enter Network Password'?
each time I open Outlook, the Enter Network Passwork box pops up and will not go away. I do not know my password to get rid of the box. I have typed all of the passwords I can think of but no success. What do I need to Do? I can not use outlook with the box popping up every 1/2 second. Make sure you have the right passsword? -- Bill Rodgers MVP "Beckiboo" <Beckiboo@discussions.microsoft.com> wrote in message news:770EB7F5-697F-45E3-BB7F-B74F3E5ACD20@microsoft.com... > each time I open Outlook, the Enter Network Passwork box pops up and will > not > go away. I...

Problem re-loading Office 2003
I have a fully certified copy of Office 2003 which was working fine and no problems at all - but after the hard-drive failed on my Vaio pc - I had to use the emergency disc to recover the XP system after a new hard-drive was installed. All my old programmes loaded like a dream - except Office 2003 that started the set up and then an error message came up - Waiting for cabinets to be cached - then missing file L2561412 and set up failed. I trawled through the web to try and find a solution and someone suggested that this was because 2003 was not locating the CD drive to locate...

Outlook 2003 Reminder for Past Appointments
This was a follow up on a previous post about reminders in outlook. I was looking for a way to turn off reminders for all items that I added prior to the current date and time (which was truely annoying). I could not find any setting that does this in outlook if you know of one please let me know! What I ended up doing is writing some code to turn them off when the appointment is added and I have listed it below for anyone else that is annoyed by this "feature". To use it just open outlook go to tools, macro, visual basic editor and paste the code in there. You will have to allo...

Outlook Express Visual C++ Runtime Library Run-Time Error
I have a friend who's using Outlook Express 6 and is getting an "abnormal program termination" error whenever he attempts to attach a graphic file within Outlook Express. He reports that it works fine when using the Explorer shell to call OE. My friend has WinXP Home. Any advice? Jay ...

[Publisher 2003] Print large format on single page?!
Hello, can anyone tell me how I can print a large-format poster on one single smaller page? (I only find the option for distributing the poster on several pages.) Thanks! Frank Will your printer print a large format poster? -- JoAnn Paules MVP Microsoft [Publisher] "Frank Peters" <frank123.nospam@web.de> wrote in message news:c9078d$h9b$03$1@news.t-online.com... > Hello, > > can anyone tell me how I can print a large-format poster on one single > smaller page? (I only find the option for distributing the poster on > several pages.) > > Thanks! Fran...

App Unicode call MBCS dll
Hi!, I've got a great problem, and I don't have any idea how can I to solve it. I hope that there is a solution to solve it :-). Well. I've got an App UNICODE that call a routine in a dll MBCS: App UNICODE CString dir; bDameValorINI (dir, "Directorios", "Ejecutables", "C:\", true); Routine dll MBCS bool bDameValorINI (CString &valor, const CString &clave, const CString &variable, const CString &nombre_ficheroINI, bool obligatorio); When I try to call to that function, I can see with Debug that clave is only "D&qu...

Comparison of MS Money 2000 and MS Money 2003
I just upgraded and recently noticed with my transactions in comparison to MS Money 2000 which is much better and worked with all my SB Office Business tools 2000. MS Money 2003 SB Edition destroyed all links to MS Business Tools and also does not pick up all my financial transactions data so I would have to keep a paper copy anyway or go online to find the transaction to fill in the data. MS Money 2003 does not work properly with VersaCheck QuickPass 2004. TaxCut 2004 works great with MS Money 2003. You are pushing to upgrade MS Money 2005 and I read some of the support issues. In...

WSAEPROVIDERFAILEDINIT problem from service
I run from service process with user rights (when user is logged) and in this process I create socket (CAsyncSocket::Create(port);). And I get WSAEPROVIDERFAILEDINIT error. When I run this process manually everything is ok. What is wrong? There are issues of server privileges involved. One thing you might try is to use other than the LocalService account to run the service. joe On Tue, 11 Oct 2005 17:37:45 +0200, ragi <ragi@agora.pl> wrote: >I run from service process with user rights (when user is logged) and in >this process I create socket (CAsyncSocket::Create(port)...

Anyone using Web Add-ins?
I just want to see if anyone is using any web add-in programs? If you are could you please link me to your web site and tell me who's adding your using. We have a yahoo website and I just want to see how I can get it to work with RMS since thats one of the reason I bought. I really do not want to have to change the look and feel out our website I just want it to link to RMS but I open for suggestion from current web users. Our web site is www.cupolosports.com ...

lower web page to fit under godaddy banner
When I post ot a goddady free account the web sit is of to the right and novisible because of the top of the page is on the end of the banner This occurs because Publisher webs use absolute positioning in the code. No one has found a practical fix for this. Sorry, but your choices are to use paid hosting without the banner, find other free hosting, or switch to different software to produce your site. If you have a follow up question or other questions about Publisher webs, then in the future please post in the web group and we will try to help you there: news://msnews.microsoft.com/mi...