aspose file tools*
The moose likes Android and the fly likes error while connecting to webservices Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "error while connecting to webservices" Watch "error while connecting to webservices" New topic
Author

error while connecting to webservices

Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
hi,

following is my code for consuming webservices using SOAP.the webservice written in .net to insert a valueinto teh database.



getting this error in my phone
localhost/127.0.0.1:3601-connection refused


can anyone tell me what might be the problem???
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
these are the consts

Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

Are you running the application in the emulator?
In this case, localhost/127.0.0.1 points to the emulator itself.
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1479
    
    6

Localhost is device's own loopback interface, if you're trying to access your development machine use 10.0.2.2.


Swastik
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
hi...
thanks for the post
i have changed to


it says connection timed out now
i am running on my mobile
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1479
    
    6

Suzzane,

In my post by device what I wanted to say is emulator, not a real device. If you wish to connect it from real device, you need to use the actual ip address or dns name of the server.
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
thanks swastik,

i have made the changes n now trying with the emulator first runnig on local host.
coded as follwos


now my logcat says:


can you plesae tell me why such error



Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1479
    
    6

attr value delimiter missing! (position:START_TAG <html dir='null'>


So what looks is the xml being returned from the web service is not valid.
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

I'm not sure if this causing you a problem but your SOAP_ACTION stills point to localhost while you specify in the NAMESPACE points to 10.0.2.2
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

You can also use Wireshark to intercept traffic and see what is really going on.
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
i get same error when do this:

in my code i have given a toast after soap action which is not getting executed...somewhere i think it is unable to do SOAP_ACTION
anysuggestions
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
anyhelp??
m looking for suggestions
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
can anyone please tell me why dis error comes??

03-28 10:53:41.333: E/Error 879): Error on soapPrimitiveData() attr value delimiter missing! (position:START_TAG <html dir='null'>@2:11 in java.io.InputStreamReader@44c2d190)
followed my xmlpullparserexception.

i am strugling since 3 days....please help


thanks
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Sounds like the XML is not well-formed. Without seeing the complete XML there's not much we can suggest.
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
hanks,
but how can i look at the xml???
is there something to be done in the code while passing parameter

thanks
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
my android code is:




the .net webservice code:



<%@ WebService Language="C#" Class="WebServiceDemo" %>

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Data.SqlClient;


[WebService(Namespace = "http://tempuri.org/", Description = "Webservice dimostrativo per JavaScript SOAP Client")]
public class WebServiceDemo : WebService
{

[WebMethod(Description = "Hello World!")]
public string HelloWorld()
{
return "Hello World!";
}

[WebMethod(Description = "Hello [YOUR NAME HERE]")]
public string HelloTo(string name)
{
//return "Hello " + name + "!";
int count = 1;
int rows;
//string shital = "www.ixifoto.com";
//SqlConnection myConnection = new SqlConnection(@"Data Source=208.91.198.196.76;Initial Catalog=webdata;User Id=ixi;Password=web1234;");
SqlConnection myConnection = new SqlConnection(@"Data Source=209.62.85.76;Initial Catalog=Ils;User Id=ibase;Password=123456;");

try
{
myConnection.Open();
SqlCommand myCommand = new SqlCommand();
myCommand.Connection = myConnection;
// myCommand.CommandText = "insert into test123 (rec_name,city)values('" + shital + "','" + name + "')";
myCommand.CommandText = "insert into test123 (city)values('" + name + "')";
myCommand.Parameters.Add("@value", SqlDbType.VarChar).Value = name;
//rows = myCommand.ExecuteNonQuery();
myCommand.ExecuteNonQuery();

//SqlDataReader myReader = myCommand.ExecuteReader();

}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
myConnection.Close();
}

return "Done!!!";




}

should i post the xml soap which comes under the webservices when executed?
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

You can use tools like tcpmon or Eclipse TCP/IP Monitor to view what is being sent and received.
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
the xml for request response as follows:
POST /test11/demos/dotnet/webservicedemo.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/HelloTo"

<?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>
<HelloTo xmlns="http://tempuri.org/">
<name>string</name>
</HelloTo>
</soap:Body>
</soap:Envelope>
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>
<HelloToResponse xmlns="http://tempuri.org/">
<HelloToResult>string</HelloToResult>
</HelloToResponse>
</soap:Body>
</soap:Envelope>
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
please someone tell me....where lies the solution for this...searching long in google....couldnt find the solution


same error
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Are you sure that's what the code is throwing the exception for? It does not contain what the exception says:<html dir='null'> ...
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
1)when run on emulator with constants






logcat says:







Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
i found that the exception posted above comes when i run on emulator.whereas when i run from the real device with functions changed


then the logcat says:





can you please tell me why this exception on phone..
i got the wifi connection also

Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
i found that the exception posted above comes when i run on emulator.whereas when i run from the real device with functions changed


then the logcat says:





can you please tell me why this exception on phone..
i got the wifi connection also

Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
The device doesn't seem to be on the local network.
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
and how do i check that....i have given the ip as well....
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Is the device on your local WLAN? Then it should work. If you're using the connectivity of your phone provider then you can't connect to a local address like 192.168.0.43
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
now i am trying with the emulator




now the logcat says something like this:

please help

Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
i want to get it done using emulator first on localhost.
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
hello,


i have removed my exception now giving proper namespace and url




my output at logcat says:





but my value is not getting inserted into the database inspite of getting the response correct


please suggest...im just a step away i think
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
i am facing problem in passing parameter to the webservice....

i have used simple request.addProperty("name","value");

any suggestions to solve this???
would be grtfull
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
i have solved my problem now in emulator,
any idea how to run on actual device???
please help
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1479
    
    6

Everything should be same, except the ip address. You need the actual ip address or the dns name of the server.
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
iam running app on local server..giving my machine ip in the phone is not solving it......
any help??
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
hi..
please help with this...
iam trying to send a binary string to the server but getting exception as


server is receiving null

my converting to string as


the soap code is

please help me.....as i am stuck here since long...i would be greatfull if someone really provides an idea

thankyou
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Not knowing what the app is sending, nor what the server is expecting, makes it just about impossible to advise.
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
my andriod app is sending image as base64string.....server is recieving and inserting into sql server database.....the exception is strange and cant get solution anywhere...before i have successfully inserted string into databse via webservice...cant get this....

plsss help

thanks
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
please help
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
If it's an image, then I wouldn't use SOAP, I'd just use HTTP.

There isn't nearly enough information for us to help with debugging. Talk with the author of the WS and get him to help you. He should be in a position to provide you with an example of what SOAP the WS expects. Then you need to ensure that that is what you are sending.
Suzzane Pinto
Ranch Hand

Joined: Feb 10, 2012
Posts: 214
how can i send it using http??without server side script.. my webservice is written in .net.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
I've no idea about .Net, sorry. For sending, you'd use the HttpClient library (which is part of Android). The extensive documentation and example code on its web site will tell you all you need to know about it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error while connecting to webservices