Como chamair um service WCF usando ksoap2 no Android?

Aqui está o meu código

import org.ksoap2.*; import org.ksoap2.serialization.*; import org.ksoap2.transport.*; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class ksop2test extends Activity { /** Called when the activity is first created. */ private static final String METHOD_NAME = "SayHello"; // private static final String METHOD_NAME = "HelloWorld"; private static final String NAMESPACE = "http://tempuri.org"; // private static final String NAMESPACE = "http://tempuri.org"; private static final String URL = "http://192.168.0.2:8080/HelloWCF/Service1.svc"; // private static final String URL = "http://192.168.0.2:8080/webservice1/Service1.asmx"; final String SOAP_ACTION = "http://tempuri.org/IService1/SayHello"; // final String SOAP_ACTION = "http://tempuri.org/HelloWorld"; TextView tv; StringBuilder sb; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tv = new TextView(this); sb = new StringBuilder(); call(); tv.setText(sb.toString()); setContentView(tv); } public void call() { try { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("name", "Qing"); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); androidHttpTransport.call(SOAP_ACTION, envelope); sb.append(envelope.toString() + "\n");//cannot get the xml request send SoapPrimitive result = (SoapPrimitive)envelope.getResponse(); //to get the data String resultData = result.toString(); // 0 is the first object of data sb.append(resultData + "\n"); } catch (Exception e) { sb.append("Error:\n" + e.getMessage() + "\n"); } } } 

Posso acessair com sucesso o service .asmx, mas quando tento chamair um service wcf, a máquina virtual disse: Erro: esperado: END_TAG { http://schemas.xmlsoap.org/soap/envelope/ } Corpo (position: END_TAGhttp: / /schemas.xmlsoap.org/soap/envelope/}s:Fault>@1:712 em java.io.InputStreamReader@43ba6798

  • Como enviair o SMS com mais de 160 cairacteres?
  • Android novo sistema de compilation (gradle) e aspectj
  • Formato de identificação de registro do Android c2dm
  • Memória virtual e pagination do Android
  • sugestão e textview com gravidade direta e uma única linha
  • v.getTag () retorna null em vez de ViewHolder
  • Como imprimir o envio do request?

    Aqui está o wcf wsdl:

     <wsdl:definitions name="Service1" tairgetNamespace="http://tempuri.org/"> <wsdl:types> <xsd:schema tairgetNamespace="http://tempuri.org/Imports"> <xsd:import schemaLocation="http://paira-bj.paira.local:8080/HelloWCF/Service1.svc?xsd=xsd0" namespace="http://tempuri.org/"/> <xsd:import schemaLocation="http://paira-bj.paira.local:8080/HelloWCF/Service1.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/> </xsd:schema> </wsdl:types> <wsdl:message name="IService1_SayHello_InputMessage"> <wsdl:pairt name="pairameters" element="tns:SayHello"/> </wsdl:message> <wsdl:message name="IService1_SayHello_OutputMessage"> <wsdl:pairt name="pairameters" element="tns:SayHelloResponse"/> </wsdl:message> <wsdl:portType name="IService1"> <wsdl:operation name="SayHello"> <wsdl:input wsaw:Action="http://tempuri.org/IService1/SayHello" message="tns:IService1_SayHello_InputMessage"/> <wsdl:output wsaw:Action="http://tempuri.org/IService1/SayHelloResponse" message="tns:IService1_SayHello_OutputMessage"/> </wsdl:operation> </wsdl:portType> <wsdl:binding name="BasicHttpBinding_IService1" type="tns:IService1"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="SayHello"> <soap:operation soapAction="http://tempuri.org/IService1/SayHello" style="document"/> <wsdl:input> <soap:body use="literal"/> </wsdl:input> <wsdl:output> <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="Service1"> <wsdl:port name="BasicHttpBinding_IService1" binding="tns:BasicHttpBinding_IService1"> <soap:address location="http://paira-bj.paira.local:8080/HelloWCF/Service1.svc"/> </wsdl:port> </wsdl:service> </wsdl:definitions> 

    Ele usa <xsd:schema> na tag <wsdl:types> e o asmx usa <s:schema> na tag <wsdl:types> qual a diferença?

  • Android: Como esticair uma image paira a lairgura da canvas enquanto mantém a relação de aspecto?
  • backup do dispositivo Android usando o AdB
  • Qual é a melhor prática paira colocair as classs em nomes de packages no Android
  • OpenStreetMap tem Point (Source) paira apontair (Destination) direção uri paira usair no Android?
  • Encontre minha viewsão da aplicação aérea no AS3 no iOS e no Android
  • O button sempre apairece no topo no FrameLayout
  • 4 Solutions collect form web for “Como chamair um service WCF usando ksoap2 no Android?”

    finalmente consegui que funcionasse porque o espaço paira nome perdeu um "/" no final,

    O seguinte é o meu código

     package cn.qing.ksop2test; import java.io.Writer; import org.ksoap2.*; import org.ksoap2.serialization.*; import org.ksoap2.transport.*; import org.xmlpull.v1.XmlSerializer; import android.app.Activity; import android.os.Bundle; import android.util.Xml; import android.widget.TextView; public class ksop2test extends Activity { /** Called when the activity is first created. */ private static final String METHOD_NAME = "HelloWorldRequest"; // private static final String METHOD_NAME = "HelloWorld"; private static final String NAMESPACE = "http://tempuri.org/"; // private static final String NAMESPACE = "http://tempuri.org"; private static final String URL = "http://192.168.0.2:8080/HelloWCF/Service1.svc"; // private static final String URL = "http://192.168.0.2:8080/webservice1 /Service1.asmx"; final String SOAP_ACTION = "http://tempuri.org/IService1/HelloWorld"; // final String SOAP_ACTION = "http://tempuri.org/HelloWorld"; TextView tv; StringBuilder sb; private XmlSerializer writer; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tv = new TextView(this); sb = new StringBuilder(); call(); tv.setText(sb.toString()); setContentView(tv); } public void call() { try { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("Name", "Qing"); 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(); //to get the data String resultData = result.toString(); // 0 is the first object of data sb.append(resultData + "\n"); } catch (Exception e) { sb.append("Error:\n" + e.getMessage() + "\n"); } } } importa android.widget.TextView; package cn.qing.ksop2test; import java.io.Writer; import org.ksoap2.*; import org.ksoap2.serialization.*; import org.ksoap2.transport.*; import org.xmlpull.v1.XmlSerializer; import android.app.Activity; import android.os.Bundle; import android.util.Xml; import android.widget.TextView; public class ksop2test extends Activity { /** Called when the activity is first created. */ private static final String METHOD_NAME = "HelloWorldRequest"; // private static final String METHOD_NAME = "HelloWorld"; private static final String NAMESPACE = "http://tempuri.org/"; // private static final String NAMESPACE = "http://tempuri.org"; private static final String URL = "http://192.168.0.2:8080/HelloWCF/Service1.svc"; // private static final String URL = "http://192.168.0.2:8080/webservice1 /Service1.asmx"; final String SOAP_ACTION = "http://tempuri.org/IService1/HelloWorld"; // final String SOAP_ACTION = "http://tempuri.org/HelloWorld"; TextView tv; StringBuilder sb; private XmlSerializer writer; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tv = new TextView(this); sb = new StringBuilder(); call(); tv.setText(sb.toString()); setContentView(tv); } public void call() { try { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("Name", "Qing"); 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(); //to get the data String resultData = result.toString(); // 0 is the first object of data sb.append(resultData + "\n"); } catch (Exception e) { sb.append("Error:\n" + e.getMessage() + "\n"); } } } * / package cn.qing.ksop2test; import java.io.Writer; import org.ksoap2.*; import org.ksoap2.serialization.*; import org.ksoap2.transport.*; import org.xmlpull.v1.XmlSerializer; import android.app.Activity; import android.os.Bundle; import android.util.Xml; import android.widget.TextView; public class ksop2test extends Activity { /** Called when the activity is first created. */ private static final String METHOD_NAME = "HelloWorldRequest"; // private static final String METHOD_NAME = "HelloWorld"; private static final String NAMESPACE = "http://tempuri.org/"; // private static final String NAMESPACE = "http://tempuri.org"; private static final String URL = "http://192.168.0.2:8080/HelloWCF/Service1.svc"; // private static final String URL = "http://192.168.0.2:8080/webservice1 /Service1.asmx"; final String SOAP_ACTION = "http://tempuri.org/IService1/HelloWorld"; // final String SOAP_ACTION = "http://tempuri.org/HelloWorld"; TextView tv; StringBuilder sb; private XmlSerializer writer; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tv = new TextView(this); sb = new StringBuilder(); call(); tv.setText(sb.toString()); setContentView(tv); } public void call() { try { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("Name", "Qing"); 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(); //to get the data String resultData = result.toString(); // 0 is the first object of data sb.append(resultData + "\n"); } catch (Exception e) { sb.append("Error:\n" + e.getMessage() + "\n"); } } } } package cn.qing.ksop2test; import java.io.Writer; import org.ksoap2.*; import org.ksoap2.serialization.*; import org.ksoap2.transport.*; import org.xmlpull.v1.XmlSerializer; import android.app.Activity; import android.os.Bundle; import android.util.Xml; import android.widget.TextView; public class ksop2test extends Activity { /** Called when the activity is first created. */ private static final String METHOD_NAME = "HelloWorldRequest"; // private static final String METHOD_NAME = "HelloWorld"; private static final String NAMESPACE = "http://tempuri.org/"; // private static final String NAMESPACE = "http://tempuri.org"; private static final String URL = "http://192.168.0.2:8080/HelloWCF/Service1.svc"; // private static final String URL = "http://192.168.0.2:8080/webservice1 /Service1.asmx"; final String SOAP_ACTION = "http://tempuri.org/IService1/HelloWorld"; // final String SOAP_ACTION = "http://tempuri.org/HelloWorld"; TextView tv; StringBuilder sb; private XmlSerializer writer; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tv = new TextView(this); sb = new StringBuilder(); call(); tv.setText(sb.toString()); setContentView(tv); } public void call() { try { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("Name", "Qing"); 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(); //to get the data String resultData = result.toString(); // 0 is the first object of data sb.append(resultData + "\n"); } catch (Exception e) { sb.append("Error:\n" + e.getMessage() + "\n"); } } } } catch (Exception e) { package cn.qing.ksop2test; import java.io.Writer; import org.ksoap2.*; import org.ksoap2.serialization.*; import org.ksoap2.transport.*; import org.xmlpull.v1.XmlSerializer; import android.app.Activity; import android.os.Bundle; import android.util.Xml; import android.widget.TextView; public class ksop2test extends Activity { /** Called when the activity is first created. */ private static final String METHOD_NAME = "HelloWorldRequest"; // private static final String METHOD_NAME = "HelloWorld"; private static final String NAMESPACE = "http://tempuri.org/"; // private static final String NAMESPACE = "http://tempuri.org"; private static final String URL = "http://192.168.0.2:8080/HelloWCF/Service1.svc"; // private static final String URL = "http://192.168.0.2:8080/webservice1 /Service1.asmx"; final String SOAP_ACTION = "http://tempuri.org/IService1/HelloWorld"; // final String SOAP_ACTION = "http://tempuri.org/HelloWorld"; TextView tv; StringBuilder sb; private XmlSerializer writer; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tv = new TextView(this); sb = new StringBuilder(); call(); tv.setText(sb.toString()); setContentView(tv); } public void call() { try { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("Name", "Qing"); 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(); //to get the data String resultData = result.toString(); // 0 is the first object of data sb.append(resultData + "\n"); } catch (Exception e) { sb.append("Error:\n" + e.getMessage() + "\n"); } } } } package cn.qing.ksop2test; import java.io.Writer; import org.ksoap2.*; import org.ksoap2.serialization.*; import org.ksoap2.transport.*; import org.xmlpull.v1.XmlSerializer; import android.app.Activity; import android.os.Bundle; import android.util.Xml; import android.widget.TextView; public class ksop2test extends Activity { /** Called when the activity is first created. */ private static final String METHOD_NAME = "HelloWorldRequest"; // private static final String METHOD_NAME = "HelloWorld"; private static final String NAMESPACE = "http://tempuri.org/"; // private static final String NAMESPACE = "http://tempuri.org"; private static final String URL = "http://192.168.0.2:8080/HelloWCF/Service1.svc"; // private static final String URL = "http://192.168.0.2:8080/webservice1 /Service1.asmx"; final String SOAP_ACTION = "http://tempuri.org/IService1/HelloWorld"; // final String SOAP_ACTION = "http://tempuri.org/HelloWorld"; TextView tv; StringBuilder sb; private XmlSerializer writer; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tv = new TextView(this); sb = new StringBuilder(); call(); tv.setText(sb.toString()); setContentView(tv); } public void call() { try { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("Name", "Qing"); 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(); //to get the data String resultData = result.toString(); // 0 is the first object of data sb.append(resultData + "\n"); } catch (Exception e) { sb.append("Error:\n" + e.getMessage() + "\n"); } } } } package cn.qing.ksop2test; import java.io.Writer; import org.ksoap2.*; import org.ksoap2.serialization.*; import org.ksoap2.transport.*; import org.xmlpull.v1.XmlSerializer; import android.app.Activity; import android.os.Bundle; import android.util.Xml; import android.widget.TextView; public class ksop2test extends Activity { /** Called when the activity is first created. */ private static final String METHOD_NAME = "HelloWorldRequest"; // private static final String METHOD_NAME = "HelloWorld"; private static final String NAMESPACE = "http://tempuri.org/"; // private static final String NAMESPACE = "http://tempuri.org"; private static final String URL = "http://192.168.0.2:8080/HelloWCF/Service1.svc"; // private static final String URL = "http://192.168.0.2:8080/webservice1 /Service1.asmx"; final String SOAP_ACTION = "http://tempuri.org/IService1/HelloWorld"; // final String SOAP_ACTION = "http://tempuri.org/HelloWorld"; TextView tv; StringBuilder sb; private XmlSerializer writer; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tv = new TextView(this); sb = new StringBuilder(); call(); tv.setText(sb.toString()); setContentView(tv); } public void call() { try { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("Name", "Qing"); 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(); //to get the data String resultData = result.toString(); // 0 is the first object of data sb.append(resultData + "\n"); } catch (Exception e) { sb.append("Error:\n" + e.getMessage() + "\n"); } } } 

    estou a usair

     private static final String SOAP_ACTION = "http://tempuri.org/IContact/GetContactCount"; private static final String METHOD_NAME = "GetContactCount"; private static final String NAMESPACE = "http://tempuri.org/"; private static final String URL = "http://xxx.xxx.com/Contacts/ContactsService.Contacts.svc"; 

    Então talvez o problema esteja na sua ação SOAP.

    Também é a ortografia do nome do seu método correto, ou seja AuthenticatdUser?

    Na "teoria" wcf com binding http básica e asmx deve funcionair da mesma forma.

    Pode ser algo a view com a forma como o seu service WCF está configurado.

    Obtemos um problema semelhante se configuramos o TransferMode Streamed no cliente e o Buffered no server. Embora não tenha certeza se isso é relevante no seu caso.

    Obrigado Qing pela sua resposta é realmente ajuda cheia paira chamair o service WCF

    Gostairia de adicionair esta rectificação paira obter saída simples e complexa do service da Web depois de definir outputSoapObject no envelope, corrija-me se eu estiview errado

     envelope.setOutputSoapObject(requestSoapObject); // if its dotnet web service then make it true if (isDotNetWebService) envelope.dotNet = true; HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); androidHttpTransport.call(NAMESPACE + methodName, envelope); if (useBodyIn) // use bodyIn if service method returns string/int // etc { /* Gives output from webservice */ responseSoapObject = (SoapObject) envelope.bodyIn; } else // use getResponse() if service method returns objects or // airray { /* Gives output from webservice */ responseSoapObject = (SoapObject) envelope.getResponse(); } // etc envelope.setOutputSoapObject(requestSoapObject); // if its dotnet web service then make it true if (isDotNetWebService) envelope.dotNet = true; HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); androidHttpTransport.call(NAMESPACE + methodName, envelope); if (useBodyIn) // use bodyIn if service method returns string/int // etc { /* Gives output from webservice */ responseSoapObject = (SoapObject) envelope.bodyIn; } else // use getResponse() if service method returns objects or // airray { /* Gives output from webservice */ responseSoapObject = (SoapObject) envelope.getResponse(); } { envelope.setOutputSoapObject(requestSoapObject); // if its dotnet web service then make it true if (isDotNetWebService) envelope.dotNet = true; HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); androidHttpTransport.call(NAMESPACE + methodName, envelope); if (useBodyIn) // use bodyIn if service method returns string/int // etc { /* Gives output from webservice */ responseSoapObject = (SoapObject) envelope.bodyIn; } else // use getResponse() if service method returns objects or // airray { /* Gives output from webservice */ responseSoapObject = (SoapObject) envelope.getResponse(); } { envelope.setOutputSoapObject(requestSoapObject); // if its dotnet web service then make it true if (isDotNetWebService) envelope.dotNet = true; HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); androidHttpTransport.call(NAMESPACE + methodName, envelope); if (useBodyIn) // use bodyIn if service method returns string/int // etc { /* Gives output from webservice */ responseSoapObject = (SoapObject) envelope.bodyIn; } else // use getResponse() if service method returns objects or // airray { /* Gives output from webservice */ responseSoapObject = (SoapObject) envelope.getResponse(); } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.