// ---------------------------------------------------------------------------------------
// This file generated by staff_codegen
// DO NOT EDIT
#include "stdafx.h"
#include <memory>
#include <staff/utils/SharedPtr.h>
#include <staff/utils/Log.h>
#include <staff/utils/fromstring.h>
#include <staff/utils/tostring.h>
#include <staff/utils/HexBinary.h>
#include <staff/utils/Base64Binary.h>
#include <staff/common/DataObject.h>
#include <staff/common/Attribute.h>
#include <staff/common/Exception.h>
#include <staff/common/Operation.h>
#include <staff/client/ServiceFactory.h>
#include <staff/client/IProxyAllocator.h>
#include <staff/client/ICallback.h>
#include <staff/client/Options.h>
#include "myserviceProxy.h"
namespace staff
{
///////////////////////////////////////////////////////////////////////////////////////////////////////
// typedef deserializators
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
// classes implementation
// proxy allocator
class MyServiceProxyAllocator: public staff::IProxyAllocator
{
public:
MyServiceProxyAllocator()
{
try
{
staff::ServiceFactory::Inst().RegisterProxyAllocator(typeid(MyService).name(), *this);
}
STAFF_CATCH_ALL_DESCR("Failed to register proxy allocator MyService");
}
virtual staff::IService* AllocateProxy(const std::string& sServiceUri,
const std::string& sSessionId,
const std::string& sInstanceId)
{
std::auto_ptr<MyServiceProxy> tpProxy(new MyServiceProxy);
tpProxy->Init(sServiceUri, sSessionId, sInstanceId);
return tpProxy.release();
}
virtual staff::IService* AllocateProxy(const std::string& sBaseUri,
const std::string& sServiceName,
const std::string& sSessionId,
const std::string& sInstanceId)
{
std::auto_ptr<MyServiceProxy> tpProxy(new MyServiceProxy);
tpProxy->Init(sBaseUri + (sServiceName.empty() ? "MyService" : sServiceName),
sSessionId, sInstanceId);
return tpProxy.release();
}
};
MyServiceProxyAllocator tMyServiceProxyAllocatorInitializer;
// asynch proxies
// service proxy
MyServiceProxy::MyServiceProxy()
{
}
MyServiceProxy::~MyServiceProxy()
{
try
{
Deinit();
}
STAFF_CATCH_ALL;
}
void MyServiceProxy::Init(const std::string& sServiceUri, const std::string& sSessionId, const std::string& sInstanceId)
{
staff::IService::Init("MyService", sSessionId, sInstanceId);
m_tClient.Init(m_sServiceUri);
staff::Options& rOptions = m_tClient.GetOptions();
rOptions.SetSessionId(sSessionId);
if (!sInstanceId.empty())
{
staff::Operation tOperation("CreateInstance");
tOperation.Request().CreateChild("sInstanceId").SetText(sInstanceId);
tOperation.SetResponse(m_tClient.Invoke(tOperation.Request()));
if (m_tClient.GetLastResponseHasFault())
{
STAFF_ASSERT_SOAPFAULT(!tOperation.IsFault(), tOperation.GetFaultCode(),
tOperation.GetFaultString(), tOperation.GetFaultDetail()); // soap fault
STAFF_THROW(::staff::RemoteException, "Failed to invoke service: " +
tOperation.GetResponse().ToString()); // other fault
}
rOptions.SetInstanceId(sInstanceId);
}
}
void MyServiceProxy::Deinit()
{
if (!staff::IService::GetInstanceId().empty())
{
staff::Operation tOperation("FreeInstance");
tOperation.Request().CreateChild("sInstanceId").SetText(staff::IService::GetInstanceId());
tOperation.SetResponse(m_tClient.Invoke(tOperation.Request()));
if (m_tClient.GetLastResponseHasFault())
{
STAFF_ASSERT_SOAPFAULT(!tOperation.IsFault(), tOperation.GetFaultCode(),
tOperation.GetFaultString(), tOperation.GetFaultDetail()); // soap fault
STAFF_THROW(::staff::RemoteException, "Failed to invoke service: " +
tOperation.GetResponse().ToString()); // other fault
}
}
}
staff::ServiceClient* MyServiceProxy::GetClient()
{
return &m_tClient;
}
bool MyServiceProxy::test()
{
staff::Operation tOperation("test");
staff::DataObject& rdoRequest = tOperation.Request();
// synchronous call
staff::DataObject myHeader("MyHeader");
myHeader.SetText("My data.");
m_tClient.AddHeader(myHeader);
tOperation.SetResponse(m_tClient.Invoke(rdoRequest));
if (m_tClient.GetLastResponseHasFault())
{
STAFF_ASSERT_SOAPFAULT(!tOperation.IsFault(), tOperation.GetFaultCode(),
tOperation.GetFaultString(), tOperation.GetFaultDetail()); // soap fault
STAFF_THROW(::staff::RemoteException, "Failed to invoke service: " + tOperation.GetResponse().ToString()); // other fault
}
const staff::DataObject& rdoResult = tOperation.ResultOpt();
bool tReturn = 0;
STAFF_ASSERT(rdoResult.GetValue(tReturn), "Invalid value for element tReturn");
return tReturn;
}
// ----------------------------------------------------------------------------------