Webmethod call from a C++ ATL console Application - c++

I am trying to call a .net webservice from a C++ ATL console Application. This is how my webmethod looks like:
[WebMethod]
public string[] GetFieryIP(string companyname)
{
IpAddress = new string[]{"1","2","3","4"};
return IpAddress;
}
In the c++ application, I have added a web reference.This is how i am accessing the webmethod:
BSTR str = SysAllocString(L"");
BSTR *ptr = new BSTR[4];
int ptr1;
HRESULT hr = ws.GetFieryIP(str, &ptr, &ptr1);
ws is the webservice proxy.
Is this correct? If yes, How do i get the IpAddress from the *ptr. I am new to C++ and dont have much idea abt pointers and COM.Please help.

Related

Get cookie from CDHtmlDialog

In my MFC application i have a derived CDHtmlDialog class that opens a login screen and i need to get a url and a cookie from the server after a redirect.
I navigate to the url inside the OnInitDialog and catch the redirect inside OnNavigateComplete:
void CDMYHtmlDlg::OnNavigateComplete(LPDISPATCH pDisp, LPCTSTR szUrl)
{
BSTR *bstr = nullptr;
this->GetDHtmlDocument(&this->m_spHtmlDoc);
if (this->m_spHtmlDoc != nullptr)
this->m_spHtmlDoc->get_cookie(bstr);
}
but the GetDHtmlDocument is returning E_NOINTERFACE, should i implement him? if yes how do i get the IHTMLDocument2?.
So my question is why i can't get the document and is this the right way to get a cookie?
Thank's in advance and sorry for my bad English.
Finally figured it out.
Inside the CDHtmlDialog class the OnNavigateComplete method is responsible for assigning value to m_spHtmlDoc but since i overwritten the method no ones assign value to the document, not even the OnDocumentComplete so the simple solution is
void CDHtmlDlgPersonalizado::OnNavigateComplete(LPDISPATCH pDisp, LPCTSTR szUrl)
{
/*CALL THE PARENT METHOD*/
CDHtmlDialog::OnNavigateComplete(pDisp, szUrl);
/*Now GetDHtmlDocument will get the value from m_spHtmlDoc and assign to spHtmlDoc*/
IHTMLDocument2Ptr spHtmlDoc = nullptr;
this->GetDHtmlDocument(&spHtmlDoc);
if (spHtmlDoc != nullptr)
{
BSTR bstr = ::SysAllocString(L" ");
spHtmlDoc->get_cookie(&bstr);
}
}

WSDL imported with C++ Builder Wizard (C++ Builder Xe6 Pro)

i am pretty lame with using wsdl importer wizard with c++ Builder (XE6 Pro)
but finnally managed to properly import EBAY WSDL:
http://developer.ebay.com/webservices/latest/ebaySvc.wsdl
I can successfully run simple calls, but problem arises , when trying to set (or get )
Enum values.
At this point i am getting beautifull access violation after compilation.
Relevant piece of code:
void __fastcall TEbay::IndexBClick(TObject *Sender)
{
CallName="GetMyeBaySelling";
UnicodeString PUrl = MakeLink();
_di_eBayAPIInterface EbayCall = GeteBayAPIInterface(false,PUrl,HTP1);
CustomSecurityHeaderType *HDR = new RequesterCredentials;
HDR->eBayAuthToken=AuthToken;
HDR->Credentials = new UserIdPasswordType();
HDR->Credentials->AppId=AppId;
HDR->Credentials->DevId=DevId;
HDR->Credentials->AuthCert=CertId;
_di_ISOAPHeaders headers = EbayCall;
HTP1->SOAPHeaders->Send(HDR);
HTP1->SOAPHeaders->SetOwnsSentHeaders(True);
//GeteBayOfficialTimeRequest TR = new GeteBayOfficialTimeRequestType();
GetMyeBaySellingRequest *TR = new GetMyeBaySellingRequest();
GetMyeBaySellingResponse *ER =new GetMyeBaySellingResponse();
//ShowMessage(PUrl);
TR->Version=Version;
TR->ErrorLanguage="en_GB";
// This one raises error
TR->SoldList->OrderStatusFilter=OrderStatusFilterCodeType::All;
ShowMessage("2");
ER = EbayCall->GetMyeBaySelling(TR);
TDateTime ACK = ER->Timestamp->AsDateTime;
ShowMessage(UnicodeString("ODP:")+ACK);
// EbayCall->GeteBayOfficialTime(ER);
delete TR;
delete ER;
delete HDR;
}
Violation comes when i try to set up OrderStatusFilter or any enum values.
Declaration: (ebasvc.h) :
enum class OrderStatusFilterCodeType /* "urn:ebay:apis:eBLBaseComponents"[GblSmpl] */
{
All,
AwaitingPayment,
AwaitingShipment,
PaidAndShipped,
CustomCode
};
class OrderStatusFilterCodeType_TypeInfoHolder : public TObject {
OrderStatusFilterCodeType __instanceType;
public:
__published:
__property OrderStatusFilterCodeType __propType = { read=__instanceType };
};
I am getting mad allready with this, could anybody help me run this $#&^#$&^ ??
Best regards
TR->SoldList->OrderStatusFilter=OrderStatusFilterCodeType::All;
Looks like you are trying to assign a value to a property on the SoldList object, yet I can't see where you have created that object. Try the following.
TR->SoldList = new ItemListCustomizationType();
TR->SoldList->OrderStatusFilter=OrderStatusFilterCodeType::All;

Wrong marshaling

I developed an out-of-proc server and trying to marshal input params, but it fails.
My .idl file is:
[
uuid(6a4791c0-f69f-4d78-a591-f549c90c0620),
object,
oleautomation
]
interface IBrowserInterraction : IUnknown
{
HRESULT Unlock([in] BSTR str, [in] int value);
};
[
uuid(4d36f1c6-9ee6-4d9a-b0aa-6b7195cc5666),
version(1.0)
]
library BrowserInterractionInterfaceLibrary
{
[
uuid(cdebf15b-f12c-4559-a6ac-81620c5056c4)
]
coclass BrowserInterractionInterface
{
interface IBrowserInterraction;
};
};
My server code:
m_bpFactory = boost::make_shared<BrowserPluginInterractionClassFactory>(m_synchronizer);
IUnknown* pUnk;
m_bpFactory->QueryInterface(__uuidof(IUnknown), (void**)&pUnk);
CoRegisterClassObject(__uuidof(BrowserInterractionInterface), pUnk, CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, &magic);
My client code:
std::string data("some value")
std::wstring wstr = std::wstring(password.begin(), password.end());
BSTR bs = SysAllocStringLen(wstr.data(), wstr.size());
IBrowserInterraction* interraction = NULL;
CoCreateInstance(__uuidof(BrowserInterractionInterface), NULL, CLSCTX_ALL, __uuidof(IBrowserInterraction), (void**)&interraction);
interraction->Unlock(bs, 123);
I debugged this client call it sends the right value. But server receives this:
I created a proxy\stub library, registered it with regsvr, and included _i.c and _h.h files in client and server code, and everythong was fine.
And client after call of Unlock functions shows me this error:
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

Service which provides interface-impelementation instead of data

Since a while now I'm implementing services whenever possible with ServiceStack (or WebAPI) instead of WCF.
What I want to do now is sending an interface (-name) to the server and get a class-implementation back. Maybe that's confusing, so I'll give you an example:
My service-client has multiple operations - like "check form":
The logic for checking this form is not implemented. What it has is an interface called IFormChecker with methods like NameIsValid(string firstName, string middleName, string lastName).
Instead of sending the whole form-data to the server for validation, the client will request the implementation of IFormChecker from the server.
I know that's possible with WCF, but I have no idea how to do that with ServiceStack.
If that's possible, what's the way to go? I checked the documentation, but I'm not really wiser.
It seams like there's no "magic trick" or anything.
I have to serialize/deserialize the class "old-fashion way".
If you're interested, here's the solution:
I created a "Root"-Interface, in this example it is IModule.
This IModule contains only 1 property, called Name.
It is a string and only there for convenience:
The IFormChecker from the example would be derived from this interface:
My client knows the value of this Name-property and of course the interface itself.
It will now fire the Name-value to the server, which will return the serialized class.
All I have to do is:
var module = ModuleImplementations.FirstOrDefault(x => x.Name == name);
if(module == null) throw new SomeException();
return module.Serialize();
client-wise I can deserialize it and cast it to the interface. That's it.
Here's my ModuleSerialization-Class:
public static class ModuleSerialization
{
public static string Serialize(this IModule m)
{
using (var ms = new MemoryStream())
{
var bf = new BinaryFormatter();
bf.Serialize(ms, m);
return Convert.ToBase64String(ms.ToArray());
}
}
public static T Deserialize<T>(string serialized) where T : class, IModule
{
var ba = Convert.FromBase64String(serialized);
using (var s = new MemoryStream(ba))
{
var bf = new BinaryFormatter();
return bf.Deserialize(s) as T;
}
}
}
Cheers!

C++ Nice "name" for own function

I have a class in C++ (VS2010).
This class has public functions, for example "ToString".
Sometimes it happens that I need to call ToString from within the class.
For example:
void::ConvertToLowerCase()
{
wstring ws;
ws = ToString();
ws = lower(ws);
m_wsText= ws
}
I would like to know if I can add an "owner" to the ToString line, for example
ws = self.ToString();
or
ws = me.ToString();
I tried all names that I could imagine, but I did not find any that would work.
Having such an owner name helps me to figure out where the function resides.
In C++ you can do this via this:
ws = this->ToString(); //this is a pointer
but called in that context, this is equivalent to what you already have:
ws = ToString();
this pointer:
ws = this->ToString();