I have been successful in sending back a single structure, but I 
currently want to send back an array of structures (so the below code 
is running on my SOAP server_. My struct looks like this (and will 
get more complicated once I get it working)

struct myEvent{
        char *  time;
        char *  eventType;
        int     procPID;
        char *  procName;
};

I also have a structure for the return type of my function like

struct ns__dynEventArray{
        struct myEvent * __ptr;
        int     __size;
};

and the function is defined like 

int ns__receiveEvents(int maxEventsReturned, struct ns__dynEventArray 
&result);

I store my events in a *global* 
std::vector<myEvent> myVec;

and the actual code for my function looks like this (I cut out code 
while debugging, which is why maxEventsReturned isn't used)

int ns__receiveEvents(struct soap *soap, int maxEventsReturned, 
struct ns__dynEventArray &result){
        struct ns__dynEventArray dea;
        dea.__ptr = NULL;
        dea.__size = 0;
        printf("Sending back all events\n");
        struct myEvent * ptr = (struct myEvent *)soap_malloc(soap, 
myVec.size()*sizeof(struct myEvent));
        dra.__ptr = ptr;
        dra.__size = myVec.size();
        for(unsigned int i = 0; i < myVec.size(); i++){
                ptr[i] = myVec.at(i);
                printf("ptr[%d].time = %s\n", i, ptr[i].time);
                printf("ptr[%d].eventType = %s\n", i, ptr
[i].eventType);
                printf("ptr[%d].procPID = %d\n", i, ptr[i].procPID );
                printf("ptr[%d].procName= %s\n", i, ptr[i].procName);
                ptr++;
        }
        printf("returning from receiveEvents\n");
        result = dra;
}


So I run the code, and I fill the vector with 3 events. I then call 
ns__receiveEvents. The values all look correct when they are printed 
out on the server side. But on the client side, I see something like 
this (using SOAP::Lite with trace to show full XML output):


<SOAP-ENV:Envelope xmlns:SOAP-
ENV="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:SOAP-
ENC="http://schemas.xmlsoap.org
/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"; xmln
s:ns="capture"><SOAP-ENV:Body SOAP-
ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/";><ns:rece
iveEventsBase64Response><result><item><time>2008-08-26 
21:41:53.186</time><eventType>SetValueKey</eventType><procPID>2804</pr
ocPID><procName>C:\WINDOWS\regedit.exe</procName></item><item><time
>&#9644;</time><eventType></eventType><procPID>3014709</procPID><procN
ame>A"
&#9787;&#9787;pA"&#9787;&#9787;qA"&#9787;&#9787;rA"&#9787;&#9787;sA"&#
9787;&#9787;tA"&#9787;&#9787;uA"&#9787;&#9787;vA"&#9787;&#9787;wA"&#97
87;&#9787;xA"&#9787;&#9787;yA"...
and the junk continues seemingly forever, and I have to cancel the 
client.
So basically all values, the time, eventType, procPID, and procName 
are corrupted.

Is this due to how I'm copying data from the vector to the flat 
array, or is there a problem in the setting up of my soap stuff?

Also, I had previously been calling my struct ns__myEvent, and it 
would just send back a single (well formed) element...but then I saw 
the part of the documentation that said "To encode the data type as 
an array, the name of the struct or class SHOULD NOT have a namespace 
prefix,..." so I think that was the reason I wasn't getting multiple 
elements before, right?

Thanks much

Bob




Reply via email to