我有一个肥皂体,我需要根据这个 wsdl 定义填充正确的元素。
<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>
填充元素的代码是:
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("");
发送前的请求如下所示:
<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>
不幸的是,服务器的响应很模糊,只是说尝试对数据库执行命令时发生错误。我可以查询对服务器的其他调用,而不是这个,我认为这与 udqAnswer 未正确关闭有关?
底线是我缺乏使用肥皂的经验来发现元素的填充与 wsdl 定义不同的地方。哪里错了?