Problem using structured data with sproxy-generated proxy c++ class
- by Odrade
I am attempting to communicate structured data types between a Visual C++ client application and an ASP.NET web service. I'm am having issues whenever any parameter or return type is not a basic type (e.g. string, int, float, etc).
To illustrate the issue, I created the following ASP.NET web service:
namespace TestWebService
{
[WebService(Namespace = "http://localhost/TestWebService")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public TestData StructuredOutput()
{
TestData td = new TestData();
td.data = 1729;
return td;
}
}
public class TestData
{
public int data;
}
}
To consume the service, I created a dirt-simple Visual C++ client in VS2005. I added a web reference to the project, which caused sproxy to generate a proxy class for me. With the generated header properly included, I attempted to invoke the service like this:
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
Service1::CService1 ws;
Service1::TestData td;
HRESULT hr = ws.StructuredOutput(&td); //data is returned as expected
CoUninitialize();
return 0;
} // crashes here with access violation
The call to StructuredOutput returns the data as expected, but an access violation occurs on destruction of the CService1 object.
The access violation is occurring here (from atlsoap.h):
void UninitializeSOAP()
{
if (m_spReader.p != NULL)
{
m_spReader->putContentHandler(NULL); //access violation
m_spReader.Release();
}
}
I see the same behavior when using a TestData object as an input parameter, or when using any other structured data types as input or output. When I use basic types for input/output from the web service I do not experience these errors.
Any ideas about why this might be happening? Is sproxy screwing something up, or am I?
NOTE: I'm aware of gSOAP and the wsdl2h tool, but those aren't freely available for commercial use (and nobody here is going to buy a license). I am open to alternatives for generating the c++ proxy, as long as they are free for commercial use.