我一直在努力尝试使用ksoap2为Android构建正确的SOAP请求数小时而没有运气.理想的请求如下所示:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthorizationToken xmlns="http://www.avectra.com/2005/">
<Token>string</Token>
</AuthorizationToken>
</soap:Header>
<soap:Body>
<ExecuteMethod xmlns="http://www.avectra.com/2005/">
<serviceName>string</serviceName>
<methodName>string</methodName>
<parameters>
<Parameter>
<Name>string</Name>
<Value>string</Value>
</Parameter>
</parameters>
</ExecuteMethod>
</soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
我使用以下代码生成我的请求:
SoapObject request = new SoapObject(NAMESPACE, METHOD);
request.addProperty("serviceName", SERVICENAME);
request.addProperty("methodName", METHODNAME);
SoapObject nestedParameters = new SoapObject(NAMESPACE, "parameters");
SoapObject param = new SoapObject(NAMESPACE, "Parameter");
param.addProperty("Name", name);
param.addProperty("Value", value);
nestedParameters.addSoapObject(param);
request.addSoapObject(nestedParameters);
SoapSerializationEnvelope envelope =
new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.headerOut = new Element[1];
Element header = new Element().createElement(NAMESPACE, "AuthorizationToken");
Element …
Run Code Online (Sandbox Code Playgroud) 下面是我的代码,我用它来验证用户登录凭据.使用.net编写的Web服务
private static final String SOAP_ACTION = "http://tempuri.org/getCredentials";
private static final String OPERATION_NAME = "getCredentials";
private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ADDRESS = "http://myStaticIP:portNo/WebSiteName/CommunicationInterface.asmx";
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);
request.addProperty("username",Username);
request.addProperty("password", Password);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httptransport = new HttpTransportSE(SOAP_ADDRESS);
try
{
httptransport.call(SOAP_ACTION, envelope);
SoapPrimitive result = (SoapPrimitive) envelope.getResponse();
String value = result.toString();
value_LoginWS = value;
val = value;
login_status = Boolean.valueOf(result.toString());
Log.v("CS return value: -", result.toString());
return …
Run Code Online (Sandbox Code Playgroud) 我正在使用以下webservice从Android发送推送通知.当我第一次调用此Web服务时,需要花费很多时间并且Android设备上不会发送推送通知.它只在从Android调用时才会发生.它完美地作为webservice.
[WebMethod]
public string SendGcm(String serviceKey,String registrationId ,string message) {
WebClient wc=new WebClient();
wc.Headers.Add("Authorization", "key=" + serviceKey);
NameValueCollection nameValues=new NameValueCollection
{
{"registration_id", registrationId},
{"collapse_key", Guid.NewGuid().ToString()},
{"data.payload", message}
};
var resp=wc.UploadValues("https://android.googleapis.com/gcm/send",
nameValues);
var respMessage = Encoding.Default.GetString(resp);
return respMessage;
}
Run Code Online (Sandbox Code Playgroud) java web-services android-ksoap2 google-cloud-messaging android-webservice
我ksoap2
最近一直在努力.
我仍然感到困惑的是,SoapObject
和之间的确切区别是什么SoapPrimitive
.
何时使用它们.
我猜它与字符串和数组有关.这是真的吗?
我找到了一些链接,但感到困惑.
任何人都可以告诉我差异以及何时使用最简单的英语形式?
谢谢 :)
我有一个使用.NET框架实现的SOAP Web服务(.asmx),它以这种形式返回一个JSON字符串:
{ "checkrecord":[{ "rollno": "ABC2", "百分比":40, "出席":12, "遗漏":34}], "表1":[]}
现在在我的Android应用程序中,我使用ksoap以下列方式调用Web服务:
public String getjsondata(String b)
{
String be="";
SoapObject request = new SoapObject(namespace, method_NAME);
request.addProperty("rollno",b);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE android = new HttpTransportSE(url);
android.debug = true;
try
{
//android.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
android.call(soap_ACTION, envelope);
SoapPrimitive result = (SoapPrimitive)envelope.getResponse();
Log.i("myapp",result.toString());
System.out.println(" --- response ---- " + result);
be=result.toString();
if (be.startsWith("["))
{ // if JSON string is an array
JSONArr = new JSONArray(be);
System.out.println("length" + JSONArr.length());
for …
Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,我需要在第一次运行时通过SOAP调用将大量数据下载到Web服务中.然后将响应发送到一个函数,该函数转换XML并将数据存储在db文件中.
数据大小超过16MB,每次都有一个java.lang.OutOfMemoryError.
修改Web服务以提供较少量的数据不是一种选择.
有没有办法能够下载大数据?或许像InputStream?
这是我的代码
public Protocol[] getProtocols() {
String METHOD_NAME = "GetProtocols";
String SOAP_ACTION = "urn:protocolpedia#GetProtocols";
Log.d("service", "getProtocols");
SoapObject response = invokeMethod(METHOD_NAME, SOAP_ACTION);
return retrieveProtocolsFromSoap(response);
}
private SoapObject invokeMethod(String methodName, String soapAction) {
Log.d(TAG, "invokeMethod");
SoapObject request = GetSoapObject(methodName);
SoapSerializationEnvelope envelope = getEnvelope(request);
return makeCall(envelope, methodName, soapAction);
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议在这种情况下应该做些什么?
谢谢并问候Mukul
我刚刚遇到ksoap2在android应用程序中使用我自己的asp .net webservices.我在互联网上找到了很少的优秀资源,我在Android应用程序中实现了我的webservice.
以下是我使用的webservice响应:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<CheckAuthenticationResponse xmlns="http://tempuri.org/">
<CheckAuthenticationResult>boolean</CheckAuthenticationResult>
</CheckAuthenticationResponse>
</soap:Body>
</soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
为了使用上述服务,我实现了以下代码:
public static Boolean isAuthenticated(String UserName, String Password)
{
String NAMESPACE = "http://tempuri.org/";
String METHOD_NAME = "CheckAuthentication";
String SOAP_ACTION = "http://tempuri.org/CheckAuthentication";
String URL = "http://primehangout.com/primehangoutweb.asmx";
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("UserId");
pi.setValue(UserName);
pi.setType(String.class);
Request.addProperty(pi);
PropertyInfo pi2 = new PropertyInfo();
pi2.setName("Password");
pi2.setValue(Password);
pi2.setType(String.class);
Request.addProperty(pi2);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); …
Run Code Online (Sandbox Code Playgroud) 您好我正在开发一个使用Magento作为后端的Android应用程序,我正在使用magento的SOAP webervice,我已将所有产品,客户和客户地址信息添加到购物车,但是当我尝试将运送方法添加到购物车时,我收到这个错误
这是我正在尝试的代码,请帮我解决这个问题
SoapObject availableShippingMethods = new SoapObject(MAGENTO_NAMESPACE, "shoppingCartShippingList");
availableShippingMethods.addProperty("sessionId", sessionId);
availableShippingMethods.addProperty("quoteId", quoteId);
env.setOutputSoapObject(availableShippingMethods);
androidHttpTransport.call("", env);
Object resultForAvailableShippingMethods = env.getResponse();
Log.d("AvailableShippingMethods",resultForAvailableShippingMethods.toString());
Run Code Online (Sandbox Code Playgroud)
这将给我们这个输出
下面是将Shipping方法设置为CartId的代码
SoapObject shippingmethod = new SoapObject(MAGENTO_NAMESPACE, "shoppingCartShippingMethod");
shippingmethod.addProperty("sessionId", sessionId);
shippingmethod.addProperty("quoteId", quoteId);
shippingmethod.addProperty("shippingMethod", "flatrate_error");//Code for Flatrate shipping method and it is enabled in magento site
env.setOutputSoapObject(shippingmethod);
androidHttpTransport.call("", env);
Log.d("shippingMethod", shippingmethod.toString());
Object resultforShippingMethod = env.getResponse();
Log.d("ShippingMethod", resultforShippingMethod.toString());
Run Code Online (Sandbox Code Playgroud) 我正在尝试这样的事情,
在Gradle,
内部构建类型,
repositories {
maven { url 'http://ksoap2-android.googleco/svde.cmomn/2-repo'
}
Run Code Online (Sandbox Code Playgroud)
和依赖...
compile 'com.google.code.ksoap2-android:ksoap2-android:3.6.0'
Run Code Online (Sandbox Code Playgroud)
错误:无法解析依赖项
我想问以下问题.我们有一个Android和iOS移动应用程序,用于与.NET服务器交换数据.
对于Android,使用ksoap2库,而对于iOS,使用带有AEXML库的Alamofire.
我们希望为服务器和应用程序之间的通信启用加密,特别是具有相互证书的Message Security(https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/message-security - 相互证明)
我无法找到任何有关Android或iOS客户端如何加密/解密请求/响应的信息.
能否请您提供相关信息?
提前致谢!
android-ksoap2 ×10
android ×9
java ×4
ksoap2 ×4
soap ×4
web-services ×2
asp.net ×1
ios ×1
json ×1
ksoap ×1
magento-1.9 ×1
wcf ×1
wcf-security ×1
xml ×1