简体   繁体   中英

populate soap envelope

I have a soap body which I need to populate with the correct elements according to this wsdl definition.

<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://DEA.Web.Service.MasterCalendar.API/">
<s:element name="GetEvents">
 <s:complexType>
  <s:sequence>
    <s:element minOccurs="0" maxOccurs="1" name="userName" type="s:string"/>
    <s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
    <s:element minOccurs="1" maxOccurs="1" name="startDate" type="s:dateTime"/>
    <s:element minOccurs="1" maxOccurs="1" name="endDate" type="s:dateTime"/>
    <s:element minOccurs="0" maxOccurs="1" name="eventName" type="s:string"/>
    <s:element minOccurs="0" maxOccurs="1" name="location" type="s:string"/>
    <s:element minOccurs="0" maxOccurs="1" name="calendars" type="tns:ArrayOfInt"/>
    <s:element minOccurs="0" maxOccurs="1" name="eventTypes" type="tns:ArrayOfInt"/>
    <s:element minOccurs="0" maxOccurs="1" name="udqAnswer" type="s:string"/>
  </s:sequence>
 </s:complexType>
</s:element>
<s:complexType name="ArrayOfInt">
  <s:sequence>
    <s:element minOccurs="0" maxOccurs="unbounded" name="int" type="s:int"/>
  </s:sequence>
</s:complexType>
</s:schema>
</wsdl:types>

the code to populate the element is:

SOAPElement username  = bodyElement.addChildElement(sf.createName("userName","SOAP-ENV","http://DEA.Web.Service.MasterCalendar.API/"));
username.addTextNode("username");
SOAPElement password  = bodyElement.addChildElement(sf.createName("password","SOAP-ENV","http://DEA.Web.Service.MasterCalendar.API/"));
password.addTextNode("password");

SOAPElement startdate  = bodyElement.addChildElement(sf.createName("StartDate","SOAP-ENV","http://DEA.Web.Service.MasterCalendar.API/"));
SOAPElement endate  = bodyElement.addChildElement(sf.createName("EndDate","SOAP-ENV","http://DEA.Web.Service.MasterCalendar.API/"));
startdate.addTextNode("2013-02-01");
endate.addTextNode("2013-02-10");
SOAPElement eventName  = bodyElement.addChildElement(sf.createName("EventName","SOAP-ENV","http://DEA.Web.Service.MasterCalendar.API/"));
eventName.addTextNode("rock");
SOAPElement location  = bodyElement.addChildElement(sf.createName("location","SOAP-ENV","http://DEA.Web.Service.MasterCalendar.API/"));
location.addTextNode("The Well");

SOAPElement calendars  = bodyElement.addChildElement(sf.createName("calendars","SOAP-ENV","http://DEA.Web.Service.MasterCalendar.API/"));
SOAPElement calendarId  = calendars.addChildElement(sf.createName("int","SOAP-ENV","http://DEA.Web.Service.MasterCalendar.API/"));
calendarId.addTextNode("47");

SOAPElement eventTypes  = bodyElement.addChildElement(sf.createName("eventTypes","SOAP-ENV","http://DEA.Web.Service.MasterCalendar.API/"));
SOAPElement eventId  = eventTypes.addChildElement(sf.createName("int","SOAP-ENV","http://DEA.Web.Service.MasterCalendar.API/"));
eventId.addTextNode("37");
//SOAPElement eventId2  = eventTypes.addChildElement(sf.createName("int","SOAP-ENV","http://DEA.Web.Service.MasterCalendar.API/"));

SOAPElement udqAnswer  = bodyElement.addChildElement(sf.createName("udqAnswer","SOAP-ENV","http://DEA.Web.Service.MasterCalendar.API/"));
udqAnswer.addTextNode("");

The request prior to being sent looks like this:

<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Header/><env:Body>
<SOAP-ENV:GetEvents xmlns:SOAP-ENV="http://DEA.Web.Service.MasterCalendar.API/">
  <SOAP-ENV:userName>username</SOAP-ENV:userName>
  <SOAP-ENV:password>password</SOAP-ENV:password>
  <SOAP-ENV:StartDate>2013-02-01</SOAP-ENV:StartDate>
  <SOAP-ENV:EndDate>2013-02-10</SOAP-ENV:EndDate>
  <SOAP-ENV:EventName>rock</SOAP-ENV:EventName>
  <SOAP-ENV:location>The Well</SOAP-ENV:location>
  <SOAP-ENV:calendars>
     <SOAP-ENV:int>47</SOAP-ENV:int>
  </SOAP-ENV:calendars>
  <SOAP-ENV:eventTypes>
    <SOAP-ENV:int>37</SOAP-ENV:int>
  </SOAP-ENV:eventTypes>
  <SOAP-ENV:udqAnswer/>
  </SOAP-ENV:GetEvents>
 </env:Body></env:Envelope>

Unfortuantely the servers response is vague and just says An error occured attempting to execute the command against the database. I can query other calls to the server just not this one, I think it has to do with the udqAnswer being not properly closed?

Bottom line is I am lacking experince with to soap to spot where the populating of the element differs from the wsdl definition. Where is it wrong?

Try using SoapUI to just send several xml messages, and see if you can generate message for which you will get correct response.

http://www.soapui.org

Second try removing udqAnswer. I had issues with web services when I was sending empty tag because it was translated as null and there were issues about that :|

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM