2

Hello I new in webservice here i am using SOAP service and run on localhost but getting this error Here is my code: public class Neteesh extends Activity{

private static final String URL = "http://localhost:7642/Service1.asmx";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String METHOD_NAME = "HelloWorld";

private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld";

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

TextView textView = new TextView(this);

setContentView(textView);


new LongOperation().execute("");
}


private class LongOperation extends AsyncTask<String, Void, String> 
{

    @Override
    protected String doInBackground(String... HelloWorldResult) 
    {
        // TODO Auto-generated method stub

        String value = new String();
        System.out.println("Inside getLognoperation method...........");
        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("billId", HelloWorldResult);

        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        soapEnvelope.dotNet=true;
        soapEnvelope.setOutputSoapObject(request);
        AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);
        try
        {
            androidHttpTransport.call(SOAP_ACTION, soapEnvelope);
            SoapPrimitive  resultString = (SoapPrimitive)soapEnvelope.getResponse();
            value = resultString.toString();
            System.out.println("This getAccountsNames xmls is : "+value);
        }   catch (Exception e) {
            e.printStackTrace ();
        }
        return value;
    }           
}   
}

Here is my logcat:

  11-16 11:11:48.371: W/System.err(1324): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <HTML>@2:7 in java.io.InputStreamReader@4101fc30) 
11-16 11:11:48.371: W/System.err(1324):     at org.kxml2.io.KXmlParser.require(KXmlParser.java:2046)
11-16 11:11:48.371: W/System.err(1324):     at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:127)
11-16 11:11:48.381: W/System.err(1324):     at org.ksoap2.transport.Transport.parseResponse(Transport.java:63)
11-16 11:11:48.381: W/System.err(1324):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100)
11-16 11:11:48.381: W/System.err(1324):     at com.example.helloworldwebservice.Neteesh$LongOperation.doInBackground(Neteesh.java:55)
11-16 11:11:48.381: W/System.err(1324):     at com.example.helloworldwebservice.Neteesh$LongOperation.doInBackground(Neteesh.java:1)
11-16 11:11:48.381: W/System.err(1324):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
11-16 11:11:48.381: W/System.err(1324):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-16 11:11:48.391: W/System.err(1324):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-16 11:11:48.391: W/System.err(1324):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
11-16 11:11:48.404: W/System.err(1324):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
11-16 11:11:48.404: W/System.err(1324):     at java.lang.Thread.run(Thread.java:856)
11-16 11:11:48.404: W/System.err(1324): [ 11-16 11:11:48.404  1324: 1337 I/expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG Exception

Please edit question if my structure is wrong, How to solve it.I need string response which one in webservice. please help thanks in Advance..

Sagar Maiyad
  • 12,655
  • 9
  • 63
  • 99
parthpatibandha
  • 92
  • 1
  • 1
  • 14
  • Are you sure to pass a String Array in soap request object at this line `request.addProperty("billId", HelloWorldResult);` ?? – Mukesh Kumar Singh Nov 15 '13 at 08:00
  • @Mukesh Kumar Sory but this is final code Is that any require line than suggest me here... – parthpatibandha Nov 15 '13 at 08:21
  • I am not very much sure but for testing just set a String not a String array i.e. `request.addProperty("billId", "TextForId");` or `request.addProperty("billId", HelloWorldResult[0]);` and then run it. – Mukesh Kumar Singh Nov 15 '13 at 08:25
  • @Mukeshkumar I change HelloWorldResult to HelloWorldResult[0] than error was changed new error is: 11-15 14:12:51.714: W/System.err(1662): java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 7642): connect failed: ECONNREFUSED (Connection refused) 11-15 14:12:51.760: W/System.err(1662): at libcore.io.IoBridge.connect(IoBridge.java:114) – parthpatibandha Nov 15 '13 at 08:45
  • Is this emulator error??? – parthpatibandha Nov 15 '13 at 08:59
  • thanks but there are anther error: 11-15 14:32:54.754: W/System.err(1712): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {schemas.xmlsoap.org/soap/envelope}Envelope (position:START_TAG @2:7 in java.io.InputStreamReader@4101fc88) How to solve it?? thanks in advance.. – parthpatibandha Nov 15 '13 at 09:14
  • Any one have solution of this problem? – parthpatibandha Nov 15 '13 at 10:37
  • Hello everyone.. Please give me right solution!!!! thanks in advance... – parthpatibandha Nov 16 '13 at 04:44

1 Answers1

1

Since Android emulator run on Virtual Machine therefore you have to use this

private static final String URL = "http://10.0.2.2:7642/Service1.asmx";

instead of

private static final String URL = "http://localhost:7642/Service1.asmx";

And then

protected String doInBackground(String... HelloWorldResult) 
    {
      .....
      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
      request.addProperty("billId", HelloWorldResult[0]);
      .....
  }

As you are trying now...

Mukesh Kumar Singh
  • 4,512
  • 2
  • 22
  • 30
  • thanks but there are anther error: 11-15 14:32:54.754: W/System.err(1712): org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG @2:7 in java.io.InputStreamReader@4101fc88) How to solve it?? thanks in advance.. – parthpatibandha Nov 15 '13 at 09:04
  • @parthpatibandha see this answer http://stackoverflow.com/questions/12430136/ksoap2-org-xmlpull-v1-xmlpullparserexception-expected-start-tag-error – Mukesh Kumar Singh Nov 15 '13 at 09:14
  • this error occured becouse my service on localhost? or some another problem? – parthpatibandha Nov 15 '13 at 09:18
  • @parthpatibandha As discussed in this stackoverflow.com/questions/12430136/… answer, There may me no of reason of this error... take a look of google search https://www.google.co.in/search?q=org.xmlpull.v1.xmlpullparserexception+expected+start_tag&rlz=1C1CHMO_enIN508IN508&oq=org.xmlpull.v1.XmlPullParserException%3A&aqs=chrome.1.69i57j0l5.3268j0j1&sourceid=chrome&espv=210&es_sm=122&ie=UTF-8 – Mukesh Kumar Singh Nov 15 '13 at 09:22