getting java.io.IOException: HTTP request failed, HTTP status: 404 in ksoap2 while passing xml data to soap1.2 android
Asked Answered
M

2

2

i have to pass

<?xml version='1.0' encoding='utf-8' ?>
<hello><username>[email protected]</username>
<password>test</password></hello>

to

Wsdl

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="http://tempuri.org/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" name="SilentManagerAPI" targetNamespace="http://tempuri.org/">
<wsp:Policy wsu:Id="WSHttpBinding_ISilentManagerAPI_policy">
<wsp:ExactlyOne>
<wsp:All>
<wsaw:UsingAddressing/>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://myurl.com/Service.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="http://myurl.com/Service.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="ISilentManagerAPI_Service_InputMessage">
<wsdl:part name="parameters" element="tns:Service"/>
</wsdl:message>
<wsdl:message name="ISilentManagerAPI_Service_OutputMessage">
<wsdl:part name="parameters" element="tns:ServiceResponse"/>
</wsdl:message>
<wsdl:portType name="ISilentManagerAPI">
<wsdl:operation name="Service">
<wsdl:input wsaw:Action="http://tempuri.org/ISilentManagerAPI/Service" message="tns:ISilentManagerAPI_Service_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ISilentManagerAPI/ServiceResponse" message="tns:ISilentManagerAPI_Service_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="WSHttpBinding_ISilentManagerAPI" type="tns:ISilentManagerAPI">
<wsp:PolicyReference URI="#WSHttpBinding_ISilentManagerAPI_policy"/>
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Service">
<soap12:operation soapAction="http://tempuri.org/ISilentManagerAPI/Service" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SilentManagerAPI">
<wsdl:port name="WSHttpBinding_ISilentManagerAPI" binding="tns:WSHttpBinding_ISilentManagerAPI">
<soap12:address location="http://myurl.com/Service.svc/Service.svc"/>
<wsa10:EndpointReference>
<wsa10:Address>
http://myurl.com/Service.svc/Service.svc
</wsa10:Address>
</wsa10:EndpointReference>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

Code Tried :

import android.os.AsyncTask;
import android.os.Bundle;

import android.util.Log;
import android.widget.TextView;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;

import java.io.Writer;

import org.ksoap2.*;
import org.ksoap2.serialization.*;
import org.ksoap2.transport.*;
import org.xmlpull.v1.XmlSerializer;

public class MainActivity extends Activity {

    private static final String METHOD_NAME = "Service"; 
    private static final String NAMESPACE = "http://tempuri.org/"; 
    private static final String URL = "http://myurl.com/Service.svc";
    final String SOAP_ACTION = "http://tempuri.org/ISilentManagerAPI/Service";

    TextView tv;
    StringBuilder sb;
    private XmlSerializer writer;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        tv = new TextView(this);
        sb = new StringBuilder();
        new testReq().execute();
        tv.setText(sb.toString());
        setContentView(tv);
    }

    class testReq extends AsyncTask<Void, Void, Void> {
        Dialog dialog;

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
            dialog = ProgressDialog.show(MainActivity.this, "Please Wait...",
                    "Testing........");
            dialog.setCancelable(true);
            dialog.setOnCancelListener(new OnCancelListener() {

                @Override
                public void onCancel(DialogInterface dialog) {
                    // TODO Auto-generated method stub
                    cancel(true);
                }
            });

        }

        @Override
        protected void onPostExecute(Void result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            dialog.dismiss();
        }

        @Override
        protected Void doInBackground(Void... params) {
            // TODO Auto-generated method stub
            call();
            return null;
        }
    }

    public void call() {
        try {

            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

            PropertyInfo req = new PropertyInfo();
            req.name = "hello";
            req.type = String.class;
            req.setValue("<hello>" + "<username>[email protected]</username>"
                    + "<password>test123</password>" + "</hello>");
            request.addProperty(req);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(request);

            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapPrimitive result = (SoapPrimitive) envelope.getResponse();

            String resultData = result.toString();
            Log.i("Result", "" + resultData);

            sb.append(resultData + "\n");
        } catch (Exception e) {
            sb.append("Error:\n" + e.getMessage() + "\n");
            e.printStackTrace();
        }

    }
}

i am using internet permission in AndroidManifest.xml

  <uses-permission android:name="android.permission.INTERNET"/>

and output will be like

<hello>
  <username>any</username>
  <myoutputdata>
    .
    . return data
    .    
  </myoutputdata>
</silent>

After Trying this code getting exception

LogCat

08-01 13:27:53.240: W/System.err(10915): java.io.IOException: HTTP request failed, HTTP status: 404
08-01 13:27:53.300: W/System.err(10915):    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:195)
08-01 13:27:54.370: W/System.err(10915):    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:116)
08-01 13:27:54.390: W/System.err(10915):    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:111)
08-01 13:27:54.410: W/System.err(10915):    at com.example.testeset.MainActivity.call(MainActivity.java:105)
08-01 13:27:54.440: W/System.err(10915):    at com.example.testeset.MainActivity$testReq.doInBackground(MainActivity.java:80)
08-01 13:27:54.460: W/System.err(10915):    at com.example.testeset.MainActivity$testReq.doInBackground(MainActivity.java:1)
08-01 13:27:54.470: W/System.err(10915):    at android.os.AsyncTask$2.call(AsyncTask.java:264)
08-01 13:27:54.480: W/System.err(10915):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
08-01 13:27:54.490: W/System.err(10915):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-01 13:27:54.500: W/System.err(10915):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
08-01 13:27:54.500: W/System.err(10915):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
08-01 13:27:54.500: W/System.err(10915):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
08-01 13:27:54.500: W/System.err(10915):    at java.lang.Thread.run(Thread.java:856)

Here i am getting Exception:

androidHttpTransport.call(SOAP_ACTION, envelope);
Macropterous answered 1/8, 2013 at 6:52 Comment(14)
i guess this is the url api.silentmanager.com/Service.svc/Service.svc and it does not openin browserChaste
yes that's the url. #11160855. check this it has something to do with binding. not sure. why was this downvoted?Chaste
stackoverflow.com/help/bountyChaste
use BasicHttpBinding in your service instead of using WSHttpBinding. because this is advance one. still i didnt connect this binding with android. i have tried lot of method. but i can't.Mckeever
@Mckeever thanks for the comment ! i gonna try that !Macropterous
@Tarsem i am damn sure you will get output by using BasicHttpBindingMckeever
@Tarsem android-spirit.blogspot.in/2013/07/… watch this.Mckeever
@Mckeever on your provided link i tried code nothing happening on button click !Macropterous
@Tarsem its working for me anyway try this link https://mcmap.net/q/1924673/-using-web-services-in-android-closedMckeever
@Tarsem have you got the output!! if not check internet connection in your emulator.Mckeever
@Mckeever i am testing on Physical Device and my internet connection is working fine !Macropterous
@Tarsem have you found the solution or still same issue?Mckeever
let us continue this discussion in chatMckeever
Hi @PoojaKansal, I have a same problem, but accepted answer not helped me, how you solved your problem?Chinookan
B
3

If still relevant..

First of all, you should change URL to http://myurl.com/Service.svc/Service.svc. It will solve 404 error.

Further you should change

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

to

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);

Further you should add wsa:To and wsa:Action headers like this:

        Element e = new Element();
        e.setName("To");
        e.setNamespace("http://www.w3.org/2005/08/addressing");
        e.addChild(Node.TEXT,"http://myurl.com/Service.svc/Service.svc");

        Element e1 = new Element();
        e1.setName("Action");
        e1.setNamespace("http://www.w3.org/2005/08/addressing");
        e1.addChild(Node.TEXT,"http://tempuri.org/ISilentManagerAPI/Service");

        envelope.headerOut = new Element[]{e,e1};

I hope it is helpful.

Edit: Try to change req to:

 PropertyInfo req = new PropertyInfo();
        req.name = "xmlstring";
        req.namespace=NAMESPACE;
        req.type = String.class;
        req.setValue("<hello><username>[email protected]</username><password>test</password></hello>");
        request.addProperty(req);

ie change req.name to xmlstring and set namespace.

Berkeleian answered 2/8, 2013 at 14:56 Comment(2)
thanks for your help! Really its great help :), but still something is wrong i gonna correct that !Macropterous
what is purpose of http://myurl.com/Service.svc/Service.svc double Service.svcCadmarr
C
1

Try the below

PropertyInfo req = new PropertyInfo();
req.name="silent";
req.type=String.class;
req.setValue("<silent>"
+"<action>"+logon+"</action>"
+"<gameid>"+mygameid+"</gameid>"
+"<gpassword>"+mypwd+"</gpassword>"
+"<data>"
+"<username>"[email protected]+"</username>"
+"<password>"+test+"</password>"
+"</data>"
+"</silent>");
request.addProperty(req);   
Chaste answered 1/8, 2013 at 7:4 Comment(7)
do you get any status response success or failure messages. This is what i did in one of my apps and it worked for me. that's how i used to pass the xml.Chaste
no such status ! can you please try my code i have provided you the right values !Macropterous
i have also updated the question as per tried your code you can re verify! now getting nothing except blank screen !Macropterous
the xml request as per your question is right. but there is something wrong with soap serialization. it gives me exceptionsChaste
now i am also getting Exception ! logcat posted to my question !Macropterous
let us continue this discussion in chatChaste
i have solved unknownhost Exception now getting java.io.IOException: HTTP request failed, HTTP status: 404 see my updated logcat !Macropterous

© 2022 - 2024 — McMap. All rights reserved.