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.
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();
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.
I'm new to android and I want to get data from user through edittext in android and send it to server with the help of soap request i.e. in xml format,can somebody please help me reply a.s.a.p.???
You can send the request in xml format as shown in the xml below. Modify the same according to your needs.
Example. (using KSOAP2 library)
SoapObject request = new SoapObject("http://service.medal.org/", "GetPosts");
PropertyInfo getpostreq = new PropertyInfo();
getpostreq.name="GetPostsReq";
getpostreq.type=String.class;
getpostreq.setValue("<GetPostsReq>"
+"<sessionId>"+sessionid+"</sessionId>"
+"<postedAfter>"+5+"</postedAfter>"
+"<postedBefore>"+20+"</postedBefore>"
+"<radius>10</radius>"
+"<location>"
+"<latitude>"+lati+"</latitude>"
+"<longitude>"+longi+"</longitude>"
+"</location>"
+"<postedBy>all</postedBy>"
+"</GetPostsReq>");
request.addProperty(getpostreq);
SoapSerializationEnvelope envelop = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelop.setOutputSoapObject(reques
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
I'm developing an Android app which needs to connect to a .NET SOAP web service and generate/populate a number of objects from the response. I'm totally new to web services and SOAP, and relatively new to Android. The web service has already been built (not by me).
I've been trying to find info on connecting to SOAP web services in Android. The two basic suggestions seem to be:
Don't use SOAP,
If you do use SOAP, use KSOAP2.
I've looked at various tutorials for KSOAP2 but they all seem to deal only with the most basic, primitive types, such as sending 2 ints to get 1 int back, or sending and receiving strings;, however, I need to send custom objects back and forth.
Is it possible to send and receive custom objects using KSOAP2? If so, how easy/difficult is this? Does the XML have to be parsed to create/populate the objects "by hand"?
EDIT/UPDATE:
After trying for a while to connect to the existing webservice (takes a String and returns a complex object), and getting an error, I decided to try a simpler approach. I connected to a simpler webservice which takes no parameters, and returns an int. This simpler webservice is hosted in the same place as the original one, and the simple one now works fine for me.
FURTHER UPDATE:
All working fine now! Turns out I just had a capitalisation error which was throwing off my parameter.
The final problem was "national" versus "National". Here's the soapUI-generated code:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:GetClientByNationalID>
<!--Optional:-->
<tem:nationalID>XXXXXXX</tem:nationalID>
</tem:GetClientByNationalID>
</soapenv:Body>
</soapenv:Envelope>
And the request code which was being generated by my 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>
<GetClientByNationalID xmlns="http://tempuri.org/" id="o0" c:root="1">
<NationalID i:type="d:string">
XXXXXXXX
</NationalID>
</GetClientByNationalID>
</v:Body>
</v:Envelope>
My final java code is:
public void webServiceCall() {
String NAMESPACE = "http://tempuri.org/";
String METHOD_NAME = "GetClientByNationalID";
String SOAP_ACTION = "http://tempuri.org/IClientService/GetClientByNationalID";
// unsecure service
String URL = "http://XXXXXXXXXXXXXXXXXXXX.net/FPUnSecureService/ClientService.svc";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
String clientID = "XXXXXXX";
PropertyInfo pi = new PropertyInfo();
pi.setName("nationalID");
pi.setValue(clientID);
pi.setType(clientID.getClass());
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.addMapping(NAMESPACE, "GetClientByNationalID", new ClientID().getClass());
Marshal floatMarshal = new MarshalFloat();
floatMarshal.register(envelope);
HttpTransportSE t = new HttpTransportSE(URL);
ClientID client = new ClientID();
t.debug = true;
try {
Log.i("webServiceCall", "Trying call to web service");
t.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse();
Log.i("success", response.getPropertyAsString(0));
Log.i("success", response.getPropertyAsString(1));
Log.i("success", response.getPropertyAsString(2));
Log.i("success", response.getPropertyAsString(3));
Log.i("success", response.getPropertyAsString(4));
} catch (Exception e) {
Log.e("webServiceCall", "Error calling webservice.");
e.printStackTrace();
System.out.println("Request: " + t.requestDump);
System.out.println("Response: " + t.responseDump);
}
}
I am still confused about these lines:
envelope.addMapping(NAMESPACE, "GetClientByNationalID", new ClientID().
Marshal floatMarshal = new MarshalFloat();
floatMarshal.register(envelope);
I think I added the Marshal parts when I was passing an object as a parameter, I'm not sure if I still need them. I'm also not sure about the addMapping call either, and what I should have in there. Thanks.
Use ksoap2, and check my answers with code examples at the following links: Link1,link2,link3. I wrote some details which will help you understand how to start coding.
let me know if u need help.
UPDATE ( Answering your question about mapping and marshalling)
u use addMapping when you are Sending a complex type ( ie an object) through the soap envelope. How will the webservice recognize the complex type ? u need to create locally a class that implement kvmserializable (as mentionned in my links) which will have same parameter as the object on the server, and then u need to add mapping between it and the class that maps to it on the server, so that the enveloppe when parsed on the server it knows this complex type X map to class X on the server. So if you are not Sending complex type, you don't need to add mapping.(PS:I see that your not sending a complex type since nationalID is of type string. IF lets say nationalID was a complex type of type Z you would do : addMapping(NAMESPACE, Z.class.getSimpleName(), Z.class) )
As for marshalling, it uses java serialization to change Objects to stream of data to be unmarshalled on the web service. So when u are sending a complex type,based on my experience, it is a good practice to add marshalling to change the complex type to streams of data by serializing it. If you find that you don't need it just don't add it, but its always good to understand what are the options out there.
Look at this http://seesharpgears.blogspot.com/2010/10/ksoap-android-web-service-tutorial-with.html , there are examples of how to pass complex objects.