WriteSale(id, date, clientCardNumber, discountRate, items, deptId, bonuses, premiumBonuses) = "OK"; = (clientCardNumber); = (discountRate); = (deptId); //... = (date, (id), ); () = ..(); . = date; . = id; = .(); ; . = (bonuses); //... ..(); // item items.Items = (item.Code); = ..(); . = (item.Quantity); //... ; .(.); = (); ("Cafe.WriteSale - : " + , .); ; ; // "" ;
protected String call() throws Exception { result = null; HttpTransportSE httpTransport = new HttpTransportSE(uri); httpTransport.debug = true; String resultString; SoapObject request = new SoapObject(namespace, methodName); request.addProperty("id", sale.getId()); SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss"); request.addProperty("date", dateFormat.format(sale.getDate())); request.addProperty("clientCardNumber", sale.getCardNumber()); request.addProperty("bonuses", Double.toString(sale.getBonuses())); //... // see - http://code.google.com/p/ksoap2-android/wiki/CodingTipsAndTricks#Adding_an_array_of_complex_objects_to_the_request SoapObject sales = new SoapObject(namespace, "items"); for (SaleItemInformation item : sale.getSales()) { SoapObject itemSoap = new SoapObject(namespace, "Items"); itemSoap.addProperty("Code", item.getItem().getSourceCode()); itemSoap.addProperty("Quantity", Double.toString(item.getQuantity())); //... sales.addSoapObject(itemSoap); } request.addSoapObject(sales); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); // - xml envelope.implicitTypes = true; envelope.setOutputSoapObject(request); try { httpTransport.call(soapAction, envelope); } catch (Exception e) { e.printStackTrace(); throw e; } resultString = envelope.getResponse().toString(); return resultString; }
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"> <v:Header /> <v:Body> <n0:WriteSale id="o0" c:root="1" xmlns:n0="http://www.xxxxx.ru"> <date i:type="d:string">Thu May 31 16:13:08 YEKST 2012</date> <clientCardNumber i:type="d:string">120</clientCardNumber> <discountRate i:type="d:string">5.0</discountRate> <id i:type="d:long">11</id> <n0:items i:type="n0:items"> <n0:Items i:type="n0:Items"> <Code i:type="d:string">3000</Code> <Price i:type="d:string">100.0</Price> <Quantity i:type="d:string">2.0</Quantity> <Sum i:type="d:string">200.0</Sum> </n0:Items> <n0:Items i:type="n0:Items"> <Code i:type="d:string">3001</Code> <Price i:type="d:string">110.0</Price> <Quantity i:type="d:string">1.0</Quantity> <Sum i:type="d:string">110.0</Sum> </n0:Items> </n0:items> </n0:WriteSale> </v:Body> </v:Envelope>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header/> <soap:Body> <m:WriteSale xmlns:m="http://www.xxxxx.ru"> <m:id xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">1</m:id> <m:date xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">2</m:date> <m:clientCardNumber xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">3</m:clientCardNumber> <m:discountRate xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">4</m:discountRate> <m:items xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <m:Items> <m:Code>123</m:Code> <m:Price>12.2</m:Price> <m:Quantity>2</m:Quantity> <m:Sum>2</m:Sum> </m:Items> <m:Items> <m:Code>2</m:Code> <m:Price>1</m:Price> <m:Quantity>2</m:Quantity> <m:Sum>2</m:Sum> </m:Items> </m:items> </m:WriteSale></soap:Body> </soap:Envelope>
public static class SoapObjectCustom extends SoapObject { public SoapObjectCustom(String namespace, String name) { super(namespace, name); } @Override public SoapObject addProperty(String name, Object value) { PropertyInfo propertyInfo = new PropertyInfo(); propertyInfo.name = name; propertyInfo.type = value == null ? PropertyInfo.OBJECT_CLASS : value.getClass(); propertyInfo.setValue(value); // propertyInfo.setNamespace(this.namespace); return addProperty(propertyInfo); } }
//... SoapObjectCustom request = new SoapObjectCustom(namespace, methodName); //... SoapObject sales = new SoapObject(namespace, "items"); for (SaleItemInformation item : sale.getSales()) { SoapObjectCustom itemSoap = new SoapObjectCustom(namespace, "Items"); //... } //...
Source: https://habr.com/ru/post/145389/
All Articles