यहाँ मेरी कोडएंड्रॉइड पर ksoap2 का उपयोग कर डब्ल्यूसीएफ सेवा को कैसे कॉल करें?
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;
@Override
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");
}
}
}
मैं सफलतापूर्वक .asmx सेवा का उपयोग कर सकते है, लेकिन जब मैं एक WCF सेवा को कॉल करने की कोशिश आभासी मशीन ने कहा: त्रुटि: की उम्मीद: END_TAG {http://schemas.xmlsoap.org/soap/envelope/} बॉडी (स्थिति: END_TAGhttp: //schemas.xmlsoap.org/soap/envelope/} रों: दोष> @ 1: 712 [email protected]
में मुद्रित करने के लिए कैसे क्या अनुरोध भेजने
यहाँ है wcf wsdl:
<wsdl:definitions name="Service1" targetNamespace="http://tempuri.org/">
<wsdl:types>
<xsd:schema targetNamespace="http://tempuri.org/Imports">
<xsd:import schemaLocation="http://para-bj.para.local:8080/HelloWCF/Service1.svc?xsd=xsd0" namespace="http://tempuri.org/"/>
<xsd:import schemaLocation="http://para-bj.para.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:part name="parameters" element="tns:SayHello"/>
</wsdl:message>
<wsdl:message name="IService1_SayHello_OutputMessage">
<wsdl:part name="parameters" 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://para-bj.para.local:8080/HelloWCF/Service1.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
यह टैग <wsdl:types>
में उपयोग करता <xsd:schema>
और ASMX टैग <wsdl:types>
क्या अंतर है में <s:schema>
का उपयोग करता है?
शायद आप ksoap का उपयोग नहीं कर सकते हैं, क्योंकि दवलिक जेवीएम सूर्य जेवीएम जैसा नहीं है। आपको अपना स्वयं का एसओएपी पार्सर लिखना पड़ सकता है। मोबाइल डिवाइस, आईएमओ के लिए एसओएपी वास्तव में बहुत भारी है। –
लेकिन मैं सफलतापूर्वक .asmx सेवा से डेटा प्राप्त कर सकता हूं – Qing