The below Android soap xml request/resposen is printing in Eclipse. But, In Android Studio, Response is print, Request in XML format not printing.
mySample Code:
Android Ksoap Xml request
AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
httpTransport.debug = true;
httpTransport.call(SOAP_ACTION, envelope);
httpTransport.requestDump
httpTransport.responseDump
Thanks
In case someone else is having the same problem I fixed it with the trim() method.
Log.d("TAG ", ""+(androidHttpTransport.requestDump).trim());
PD: Maybe the op wasn't calling a print method.
Related
I am experiencing what I find to be a VERY strange problem currently. I have database with about 1000 records. I have a web service for fetching these and turning them into a json string. Testing this using soapui or another web service client works perfectly fine.
My problem is that when I fetch the data using ksoap2 in android it crashes, and here is the crazy part: it only crashes sometimes!?!?
After quite a bit of debugging I have noticed that the JSON i get in android is ALMOST the same as the one I get in eg. SOAPUI.
The problems I have seen are
it has removed a ":" between a key and value- eg. "id""2" instead of "id":"2"
it might be missing a '"' on either side of a key or a value. eg: "id:"2" instead of "id":"2"
An entire key has been removed, eg: "name":"myname","2" instead of "name":"myname","id":"2". Furthermore it is NOT the same place that something is removed every time...
I am seeing these errors (when I use logs) before I start parsing the json (which of course fails if it is not valid json). Ss the web service is returning the correct thing (according to SOAPUI) I'm assuming it is ksoap that somehow messes up parsing the soap response.
Keep in mind as well that it occasionally works and the json has all the data and is successfully parsed!
Here is my code calling the web service (The json is ~345.000 characters):
SoapObject request = new SoapObject(NAMESPACE, method);
input.addPropsToRequest(request);
SoapSerializationEnvelope envelope = new
SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.implicitTypes = true;
envelope.dotNet = false;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(soap_action, envelope);
String json = envelope.getResponse().toString();
I have a WSDL java based webservice and an android project.I didnt get any response from that wsdl url.
I couldn't solve this problem.
Here is Android Code Part.
try
{
SoapObject request = new SoapObject( "http://keycloud.noip.me:8081/knowledgecenterservice/webservice/ContentManagementService" , "getImageFromDistrict " );
request.addProperty( "district" , "Bangalore" );
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11 );
new MarshalBase64().register( envelope ); //serialization
envelope.encodingStyle = SoapEnvelope.ENC;
envelope.setOutputSoapObject( request );
HttpTransportSE transport = new HttpTransportSE( "http://keycloud.noip.me:8081/knowledgecenterservice/webservice/ContentManagementService" );
transport.call( "http://keycloud.noip.me:8081/knowledgecenterservice/webservice/ContentManagementService/getImageFromDistrict" , envelope );
SoapObject value = ( SoapObject ) envelope.getResponse();
text.setText(value.toString());
dialog.dismiss();
}catch(Exception e)
{
}
Try changing
androidHttpTransport.call("", envelope);
to
androidHttpTransport.call(METHOD_NAME, envelope);
To check the response from server
Install SOA Client Add-on on Mozilla Firefox.
I checked the response from server using the above specified URL i.e
http://keycloud.noip.me:8081/ekrishi/webservice/TestService?wsdl
and I happen to see that the method is not requesting for any parameters/inputs. So I don't know why did you wirte this line request.addProperty("district","Bangalore");
And I just invoked that method without any parameters and I got the error
faultcode: soap:Server -->means there's a problem on server side. So check with the person who has written this webservice.
faultstring: Fault occurred while processing.
Hope this information is useful for you :)
EDIT I have attached the snapshot of the error I got using SOA client. If everything is fine on server side, we will not get any error. I strongly believe that there's a problem on server side. Check your URL once.
See here the method is not requesting for any parameters. So no need to add -- request.addProperty("district", "Bangalore");. Below is the screenshot of that.
I feel like the URL you are using in wrong. Cross check it once.
Ive build an app that use sql ws to get data. i can get the data but because its a String I dont know how to split it into some verbals.
this is mt soqp rsponse
<?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<S:Body>
<ns2:getDataFromSqlResponse xmlns:ns2="http://myAndroidIt.gy.com/">
<return>id- 2 first name- hanane last name- yniv
</return>
</ns2:getDataFromSqlResponse>
</S:Body>
</S:Envelope>
how can i put only the id (2) into verbals?
I want to use it.
thx!
I suggest you use a library like ksoap2-android for calling Soap Webservices. You can add the library to your project with maven like this:
<dependency>
<groupId>com.google.code.ksoap2-android</groupId>
<artifactId>ksoap2-android</artifactId>
<version>3.2.0</version>
</dependency>
If you don't use maven you can find the download link for the jar here.
You can use the ksoap2 library to make soap calls like this:
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
// Here you could add things to your request like this:
request.addProperty("parameter1", 7);
request.addProperty("parameter2", "asdf");
request.addProperty("parameter3", someChildSoapObject);
SoapSerializationEnvelope envelope = new SSoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject)envelope.getResponse();
After you have your response object you can parse the values you need from the response object like this:
int id = Integer.parseInt(response.getPropertySafely("id").toString());
String someOtherProperty = resonse.getPropertySafelyAsString("someProperty");
You can find more information about how to use ksoap2-android here.
If you don't want to or can't use a soap library i would suggest you use a serializer framework like Simple to deserialize the String. You can find Simple here.
I actually once used Simple to write a small soap framework when it was impossible to use a library so I can recommend this if you can't use ksoap2-android.
I already tried reading the internet about my issue, but I could not find the right information I need, so I try to explain my issue:
I am using kSoap2 to "talk" to a webservice over SOAP.
To generate my SOAP request I use the following code:
// Generate SOAP request XML
SoapObject request = new SoapObject(PUB_NAMESPACE,
"testSoapInterface");
// Add request header
PropertyInfo requestHeader = new PropertyInfo();
requestHeader.setNamespace(PUB_NAMESPACE);
requestHeader.setName("requestheader");
// Generate username property
PropertyInfo usernameProp = new PropertyInfo();
usernameProp.setNamespace(BASE_NAMESPACE);
usernameProp.setName("username");
usernameProp.setValue(username);
// Generate applicationId property
PropertyInfo applicationIdProp = new PropertyInfo();
applicationIdProp.setNamespace(BASE_NAMESPACE);
applicationIdProp.setName("applicationId");
applicationIdProp.setValue("test");
// Add properties to requestHeader (nested)
requestHeader.setValue(new SoapObject(PUB_NAMESPACE, "requestheader")
.addProperty(usernameProp)
.addProperty(applicationIdProp));
request.addProperty(requestHeader);
Now, to serialize this, I use the following:
// Serialize SOAP request to the non .NET based SOAP server
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = false;
soapEnvelope.implicitTypes = true;
soapEnvelope.setAddAdornments(false);
soapEnvelope.setOutputSoapObject(request);
Because I am using nested soap (the requestheader consists of applicationId and username) I can imagine that this might be the cause.
I also have to use different namespaces for the different lines, which can also be a cause.
Can anybody help me on this??
Thanks!
You can use implicitTypes property of your envelope:
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.implicitTypes = true;
In this way the generated xml will not contain i:type.
Had the same Problem, seems to be impossible to use PropertyInfo without generating any i:type with it. Nice solution would be to Override AddProperty(PropertyInfo pi) so it works on any case without the i:Type.
Got three solutions to offer:
1
If u dont need the Namespace then request.AddProperty(name,value) does it!
2
U could make your request header an own SoapObject, it wont use the "i:type".
SoapObject requestHeader = new SoapObject(NAMESPACE,"requestheader");
and in the last line
request.AddSoapObject(requestHeader);
3
For me it worked to set the Version of the SoapEnvelope to "VER10" since the types are ignored then. They're still in your request but ignored.
Replace:SoapEnvelope.VER11 with:SoapEnvelope.VER10
Where ever you are creating
SoapSerializationEnvelope sEnvelop;
just assign sEnvelop.implicitTypes = true;
it will not create "i:type="d:string"" or "i:type="d:long"" inner datatype tag and web service can execute successfully
Basically I am using kSoap2 classes for Android. The client app is consuming a web service. If required I can post the code.
I surfed around to figure this out. I get following error message
expected: START_TAG{http://schemas.xmlsoap.org/envelope/}Envelope(posiiton:START_TAG#1:6 in java.io.InputStreamReader#437b40f0) when androidHttpTransport.call(SOAP_ACTION, envelope); is called.
What I gathered so far is "The xml is not parsed correctly or there was no response from the webservice server." Any suggestions?
Also, When I tried other external webservice: http://www.deeptraining.com/webservices/GetWeather, I received: IOException on androidHttpTransport.call(SOAP_ACTION, envelope);
IOException message: Host is unresolved, any idea how to solve this, here I didn't get the XmlPullParserException (may be it will show up once this is fixed).
Thanks and I appreciate your insight and time.
Anjana.
i had the same problem and i resolved it. I only wrote a wrong URL.
I have a php web service using NUSOAP.
Wrong address:
private static final String URL = "http://www.mywebsite.com/service/myservice.php?wsld";
Right address:
private static final String URL = "http://www.mywebsite.com/service/myservice.php";
I advise you to check the parameters you are passing to ksoap2, because it works fine.
Bye bye.