Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Don';无法理解gSOAP序列化期间的错误 在Windows、C和C++中使用GSOAP 2.7.17工作。_C#_C++_Xml_Xml Serialization_Gsoap - Fatal编程技术网

C# Don';无法理解gSOAP序列化期间的错误 在Windows、C和C++中使用GSOAP 2.7.17工作。

C# Don';无法理解gSOAP序列化期间的错误 在Windows、C和C++中使用GSOAP 2.7.17工作。,c#,c++,xml,xml-serialization,gsoap,C#,C++,Xml,Xml Serialization,Gsoap,我有(gSOAP)类来描述一组文件: class ns__ContainerFile { public: xsd__long fileId; xsd__string fileName; }; class ContainerFileArray { public: ns__ContainerFile *__ptr; int __size; }; class ns__Co

我有(gSOAP)类来描述一组文件:

class ns__ContainerFile
{
public:
    xsd__long           fileId;
    xsd__string         fileName;
};

class ContainerFileArray
{
public:
    ns__ContainerFile         *__ptr;
    int                       __size;
};

class ns__Container
{
public:
    xsd__long           containerId     0:1 = 0;
    xsd__string         name            0:1 = "";
    xsd__string         description     0:1 = "";
    ContainerFileArray* files           0:1 = NULL;
};

托管C++中,我分配返回数组:

ContainerFileArray gSoapArray;
gSoapArray.__size = managedArray->Length;
gSoapArray.__ptr = (ns__ContainerFile*) soap_malloc(soap, sizeof(ns__ContainerFile) * gSoapArray.__size);
上面的代码是名为ConvertArray的方法的一部分,因此调用该方法:

ns__Container unManaged;
*unManaged.files = ConvertArray(soap, managed->files->ToArray());
问题是,虽然ConvertArray似乎运行正常(我可以看到数据元素似乎在malloc’ed内存中正确填充),但在打包web服务请求的序列化步骤中,我遇到了访问冲突(I:C++代码已经发出SOAPUK返回值,逻辑返回到自动生成的GSOAP代码)。 整个过程在处理简单类型的数组(int、long等)时工作得很好,但在处理更复杂的类型(类等)时就崩溃了

如果在ConvertArray方法中,我在第3行替换:

gSoapArray.__ptr = soap_new_ns__ContainerFile(soap, gSoapArray.__size);
为了分配内存,它工作得很好

所以,我不确定我是否理解为什么。在第一种情况下,我使用soap_malloc分配一个内存块,该内存块的大小等于ContainerFile类的大小乘以托管数组中的元素数。在第二种情况下,它归结为使用soap_new来做同样的事情。如果分配的内存全部由gsoap管理,则不是同样(据我所知),为什么soap_malloc’ed版本在序列化过程中会失败

使用Visual Studio,我可以看到它在以下生成的代码中失败:

void ContainerFileArray::soap_serialize(struct soap *soap) const
{
    if (this->__ptr && !soap_array_reference(soap, this, (struct soap_array*)&this->__ptr, 1, SOAP_TYPE_ContainerFileArray))
        for (int i = 0; i < this->__size; i++)
        {    soap_embedded(soap, this->__ptr + i, SOAP_TYPE_IDCXDService__ContainerFile);
            this->__ptr[i].soap_serialize(soap);
        }
}
void ContainerFileArray::soap\u序列化(结构soap*soap)常量
{
if(this->\uuuptr&!soap\u数组\u引用(soap,this,(struct soap\u array*)和this->\uuuptr,1,soap\u TYPE\u ContainerFileArray))
对于(int i=0;i\uu size;i++)
{soap_embedded(soap,this->_ptr+i,soap_TYPE_IDCXDService__容器文件);
this->\uuuptr[i].soap\u序列化(soap);
}
}

指示符在突出显示的行上,但我怀疑它在SOAPHixC++调用中失败了。我也应该注意到,它在MalOC块中的第一个元素上失败(即:当i=0)。

gSoapArray.__ptr = soap_new_ ns__ContainerFile(soap, gSoapArray.__size);
或者更好,在gSOAP头文件中使用STL std::vector,如下所示:

#import "stlvector.h"
class ns__Container
{
public:
    xsd__long           containerId     0:1 = 0;
    xsd__string         name            0:1 = "";
    xsd__string         description     0:1 = "";
    std::vector<ns__ContainerFile> files           0:1 = NULL;
};
#导入“stlvector.h”
类ns_u_容器
{
公众:
xsd__长集装箱0:1=0;
xsd__字符串名称0:1=“”;
xsd__字符串说明0:1=“”;
std::矢量文件0:1=NULL;
};

<>基本上,Maloc在C++中是不安全的,因为实例的VMT没有初始化,所以动态方法调用会导致崩溃。

对不起,但是请您用更简单的术语解释一下最后的注释好吗?