我在 ksoap2 中使用 envelope.addMapping 函数,我需要让它生成没有 i:type 属性的项目。
这是我的代码生成的 soap 请求
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://www.w3.org/2003/05/soap-encoding"
xmlns:v="http://www.w3.org/2003/05/soap-envelope">
<v:Header>
<ApiKey xmlns="urn:example:data">APIKey</ApiKey>
</v:Header>
<v:Body>
<CreateScan xmlns="urn:example:services" id="o0" c:root="1">
<scan i:type="n3:" xmlns:n3="">
<n4:BaseUrl i:type="d:string" xmlns:n5="urn:example:data">http://www.example.com</n5:BaseUrl>
<n5:DisplayName i:type="d:string" xmlns:n7="urn:example:data">Example Scan</n7:DisplayName>
</scan>
</CreateScan>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我需要这样做<scan i:type="n3:scanItem" xmlns:n3="">生成为 <scan>
这是我的代码
package ksoap2.test;
import java.util.Hashtable;
import java.util.Vector;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransportSE;
import org.kxml2.kdom.Element;
import org.kxml2.kdom.Node;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class ksoap2 extends Activity {
/** Called when the activity is first created. */
private static final String SOAP_ACTION = "http://example.com/OperationsService.svc";
private static final String METHOD_NAME = "CreateScan";
private static final String NAMESPACE = "urn:example:services";
private static final String URL = "http://example.com/OperationsService.svc";
private AndroidHttpTransport androidHttpTransport;
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv=(TextView)findViewById(R.id.textView1);
try {
Element ApiKeyElement = new Element().createElement("", "ApiKey");
ApiKeyElement.setAttribute("", "xmlns", "urn:example:data");
ApiKeyElement.addChild(Node.TEXT, "22DF0959F20743660304CB829B3891F0");
Element[] header = new Element[1];
header[0]=ApiKeyElement;
Element request = new Element().createElement(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
// PropertyInfo scanProp = new PropertyInfo();
// scanProp.setName("scan");
// scanProp.setValue("");
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Scan s = new Scan();
s.BaseUrl="http://www.example.com";
s.DisplayName="Example";
PropertyInfo pi = new PropertyInfo();
pi.setName("scan");
pi.setValue(s);
pi.setType(s.getClass());
Request.addProperty(pi);
//request.addChild(Node.ELEMENT, scanElement);
envelope.headerOut = header;
//envelope.dotNet = true;
envelope.setOutputSoapObject(Request);
envelope.addMapping(null, "scanItem",new Scan().getClass());
envelope.dotNet =false;
String BodyClass = envelope.bodyOut.getClass().toString();
SoapObject body = (SoapObject)envelope.bodyOut;
int count =body.getPropertyCount();
//envelope.encodingStyle = "test";
//envelope.bodyOut=body;
androidHttpTransport = new AndroidHttpTransport (URL);
androidHttpTransport.debug = true;
//androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
androidHttpTransport.call(SOAP_ACTION, envelope);
Log.d("MyAPP", "----------------- " + androidHttpTransport.requestDump +"\r\n\r\n" + androidHttpTransport.responseDump);
((TextView)findViewById(R.id.textView1)).setText(androidHttpTransport.requestDump +"\r\n\r\n" + androidHttpTransport.responseDump);
} catch(Exception E) {
Log.d("MyAPP", "----------------- " + androidHttpTransport.requestDump +"\r\n\r\n" + androidHttpTransport.responseDump);
((TextView)findViewById(R.id.textView1)).setText(androidHttpTransport.requestDump+"ERROR:" +"\r\n\r\n" +androidHttpTransport.responseDump +"\r\n\r\n" +E.getClass().getName() + ": " + E.getMessage());
}
}
}
据我所知,问题出在 envelope.addMapping(null, "scanItem",new Scan().getClass());行,即使我删除了“scanItem”部分,它仍然会生成 <scan i:type="n3:" xmlns:n3="">
任何解决这个问题的帮助都会很棒。
最佳答案
看来我已经回答了我自己的问题。我所要做的就是添加行 envelope.implicitTypes = true;
关于android - 在 ksoap2 for android 中使用不带 "i:type="属性的 addMapping,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5410006/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub
我在新的Debian6VirtualBoxVM上安装RVM时遇到问题。我已经安装了所有需要的包并使用下载了安装脚本(curl-shttps://rvm.beginrescueend.com/install/rvm)>rvm,但以单个用户身份运行时bashrvm我收到以下错误消息:ERROR:Unabletocheckoutbranch.安装在这里停止,并且(据我所知)没有安装RVM的任何文件。如果我以root身份运行脚本(对于多用户安装),我会收到另一条消息:Successfullycheckedoutbranch''安装程序继续并指示成功,但未添加.rvm目录,甚至在修改我的.bas
下面的代码在我第一次运行它时就可以正常工作:require'rubygems'require'spreadsheet'book=Spreadsheet.open'/Users/me/myruby/Mywks.xls'sheet=book.worksheet0row=sheet.row(1)putsrow[1]book.write'/Users/me/myruby/Mywks.xls'当我再次运行它时,我会收到更多消息,例如:/Library/Ruby/Gems/1.8/gems/spreadsheet-0.6.5.9/lib/spreadsheet/excel/reader.rb:11