<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:fpm="http://schemas.datacontract.org/2004/07/FPMobileServices"><soapenv:header/><soapenv:Body> <tem:CommitOne> <tem:qr> <fpm:ClIEntID>8aa2f6a4-4d15-4b4c-9cac-fb2478d0d27a</fpm:ClIEntID> <fpm:CreatedBy>admin</fpm:CreatedBy> <fpm:CreatedDate>2012-03-01T19:50:37</fpm:CreatedDate> <fpm:DimensionID>8a02a339-b5a7-4c76-b95f-5891ef57736d</fpm:DimensionID> <fpm:ImageID>b76c7bcc-a8f8-49ff-94c6-08cd2e05b1a8</fpm:ImageID> <fpm:IndicatorID>4637b333-701d-4d03-a708-4de48569be84</fpm:IndicatorID> <fpm:LoanoperationNumber>6-2011-72978</fpm:LoanoperationNumber> <fpm:ModifIEdBy>admin</fpm:ModifIEdBy> <fpm:ModifIEdDate>2012-03-01T19:50:37</fpm:ModifIEdDate> <fpm:QuestionaireCompletedDate>2012-03-01T19:50:54</fpm:QuestionaireCompletedDate> <fpm:QuestionnaireID>99967f70-8161-4922-929f-03136a389ba6</fpm:QuestionnaireID> <fpm:ResultID>95fa03b5-80af-479d-9dec-f2bf94baf3cd</fpm:ResultID> <fpm:Resultweighting>0</fpm:Resultweighting> <fpm:StatusLevelID>03a91cd6-93cd-4503-a676-efa2967e82a7</fpm:StatusLevelID> <fpm:UploadID>141D6A1F-8FFD-4CA4-8073-009338F22B13</fpm:UploadID> </tem:qr> </tem:CommitOne></soapenv:Body></soapenv:Envelope>
我的Java代码生成的请求是:
<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> <CommitOne xmlns="http://tempuri.org/" ID="o0" c:root="1"> <qr> <ClIEntID>8aa2f6a4-4d15-4b4c-9cac-fb2478d0d27a</ClIEntID> <LoanoperationNumber>6-2011-72978</LoanoperationNumber> <CreatedBy i:null="true" /> <CreatedDate>2012-03-01T19:50:37</CreatedDate> <DimensionID>8a02a339-b5a7-4c76-b95f-5891ef57736d</DimensionID> <ImageID>b76c7bcc-a8f8-49ff-94c6-08cd2e05b1a8</ImageID> <IndicatorID>4637b333-701d-4d03-a708-4de48569be84</IndicatorID> <ModifIEdBy i:null="true" /> <ModifIEdDate i:null="true" /> <QuestionnaireCompletedDate>2012-03-01T19:50:54</QuestionnaireCompletedDate> <QuestionnaireID>99967f70-8161-4922-929f-03136a389ba6</QuestionnaireID> <ResultID i:type="d:string">95fa03b5-80af-479d-9dec-f2bf94baf3cc</ResultID> <Resultweighting>0</Resultweighting> <StatusLevelID>03a91cd6-93cd-4503-a676-efa2967e82a7</StatusLevelID> <UploadID i:type="d:string">8ffa3665-b691-486f-91a0-ebbe8575896c</UploadID> </qr> </CommitOne></v:Body>
两者之间的主要区别似乎是前缀/名称空间.出于某种原因,当“qr”对象到达我的.NET代码时,其所有属性都为null / zero.
我在我的java代码中尝试了两种不同的方法,试图将我的“qr”对象设置为PropertyInfo:
SoapObject request = new SoapObject(nameSPACE,METHOD_name); // build request object PropertyInfo qrPi = new PropertyInfo(); qrPi.setname("qr"); qrPi.setType(qr.getClass()); qrPi.setValue(qr); request.addProperty(qrPi);
并将我的“qr”设置为SoapObject,然后使用.addProperty:
SoapObject result = new SoapObject(nameSPACE,"qr"); result.addProperty("ClIEntID",(String) qr.getClIEntID()); result.addProperty("CreatedBy",(String) qr.getCreatedBy()); result.addProperty("CreatedDate",(String) qr.getCreatedDate()); result.addProperty("DimensionID",(String) qr.getDimensionID()); result.addProperty("ImageID",(String) qr.getimageID()); result.addProperty("IndicatorID",(String) qr.getIndicatorID()); result.addProperty("LoanoperationNumber",(String) qr.getLoanoperationNumber()); result.addProperty("ModifIEdBy",(String) qr.getModifIEdBy()); result.addProperty("ModifIEdDate",(String) qr.getModifIEdDate()); result.addProperty("QuestionnaireCompletedDate",(String) qr.getQuestionnaireCompletedDate()); result.addProperty("QuestionnaireID",(String) qr.getQuestionnaireID()); result.addProperty("ResultID",(String) qr.getResultID()); result.addProperty("Resultweighting",qr.getResultweighting()); result.addProperty("StatusLevelID",(String) qr.getStatusLevelID()); result.addProperty("UploadID",(String) qr.getUploadID()); request.addSoapObject(result);
但是这两种方法都得到了相同的结果 – 当我进入我的webservice时,我的所有“qr”对象的字段都是null.我一直在寻找StackOverflow上的类似问题,发现this,但我无法弄清楚如何将它应用到我自己的情况.
任何人都可以帮助解决这种情况吗?
解决方法 不确定我是否应该回答我自己的问题,但我已经找到了解决方案,并将其留给任何有类似问题的人.关键是不同的命名空间.在SoapUI生成的示例中,我们可以看到子元素(ClIEntID等)使用fpm命名空间,而它们上面的元素使用tem命名空间.为了明确指定这些子元素的命名空间,我改变了上面讨论的第二种方法 – 我为每个子元素创建了PropertyInfo对象,并将它们添加到SoapObject中.
而不是使用:
result.addProperty(String "ClIEntID",Object qr.getClIEntID());
我用了:
PropertyInfo pi = new PropertyInfo();pi.setnamespace(QR_nameSPACE);pi.setType(PropertyInfo.STRING_CLASS);pi.setname("ClIEntID");pi.setValue(qr.getClIEntID()); result.addProperty(pi);
当我使用所有属性执行此 *** 作时,它工作正常.
希望有一天能帮助别人!
总结以上是内存溢出为你收集整理的Ksoap2 Android – 如何为复杂对象的子属性指定命名空间?全部内容,希望文章能够帮你解决Ksoap2 Android – 如何为复杂对象的子属性指定命名空间?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)