मैं एंड्रॉइड वेब एप्लिकेशन विकसित कर रहा हूं जिसे प्रतिक्रिया के लिए वेब सेवा कनेक्ट करने की आवश्यकता है।स्थानीय xml फ़ाइल को org.ksoap2.serialization.ooapObject में कैसे परिवर्तित कर सकते हैं?
मैं वेब सेवा आमंत्रण प्रक्रिया के लिए केएसओएपी का उपयोग कर रहा हूं। मैं बचत कर रहा हूँ अगर वह स्थानीय निर्देशिका में, जैसे एक्सएमएल प्रतिक्रिया व्यक्त [kSOAP ऐसे एप्लेट या जे 2 एमई अनुप्रयोगों के रूप में विवश जावा एनवायरनमेंट के लिए एक सोप वेब सेवा क्लाइंट लाइब्रेरी है।]
। /mnt/sdcard/appData/config.xml और फिर जब भी मैं वेब सेवा के लिए अनुरोध पूछता हूं, तो पहले यह जांच करेगा कि स्थानीय फ़ाइल वहां है या नहीं, तो उस फ़ाइल को प्रतिक्रिया फ़ाइल के रूप में मानें अन्यथा सर्वर से कनेक्ट करें।
यह प्रक्रिया प्रतिक्रिया समय को कम करती है और आवेदन की दक्षता में वृद्धि करती है।
क्या यह इसे ('config.xml') को SOAP ऑब्जेक्ट में परिवर्तित करना संभव है? और कैसे?
पर विचार करें मेरी एक्सएमएल स्थानीय फ़ाइल के रूप में नीचे है:
config.xml
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<Response xmlns="http://testuser.com/webservices/response">
<Result>
<SName>Test User</SName>
<UnitDesc>SAMPLE Test </UnitDesc> <RefreshRate>60</RefreshRate>
<Out>
<Definition>
<Code>ABC</Code>
<Description>(Specific)</Description>
<Action>true</Action>
<Despatch>false</Despatch>
</Definition>
<Definition>
<Code>CDE</Code><Description>(Specific)</Description>
<ActionDate>true</ActionDate>
</Definition>
</Out>
<SampleText>
<string>Test XML Parsing</string>
<string>Check how to convert it to SOAP response</string>
<string>Try if you know</string>
</SampleText>
<GeneralData>
<Pair>
<Name>AllowRefresh</Name>
<Value>Y</Value>
</Pair>
<Pair>
<Name>ListOrder</Name>
<Value>ACCENDING</Value>
</Pair>
</GeneralData>
</Result>
</Response>
</soap:Body>
</soap:Envelope>
वर्तमान कोड नीचे दिखाया गया है:
final String CONFIGURATION_FILE="config.xml";
File demoDataFile = new File("/mnt/sdcard/appData");
boolean fileAvailable=false;
File[] dataFiles=demoDataFile.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
return filename.endsWith(".xml");
}
});
for (File file : dataFiles) {
if(file.getName().equals(CONFIGURATION_FILE))
{
fileAvailable=true;
}
}
if(fileAvailable)
{
//**What to do?**
}
else
{
//Create the envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//Put request object into the envelope
envelope.setOutputSoapObject(request);
//Set other properties
envelope.encodingStyle = SoapSerializationEnvelope.XSD;
envelope.dotNet = true;
String method="test";
synchronized (transportLockObject)
{
String soapAction = "http://testuser.com/webservices/response/"+method;
try {
transport.call(soapAction, envelope);
} catch (SSLHandshakeException she) {
she.printStackTrace();
SecurityService.initSSLSocketFactory(ctx);
transport.call(soapAction, envelope);
}
}
//Get the response
Object response = envelope.getResponse();
//Check if response is available... if yes parse the response
if (response != null)
{
if (sampleResponse != null)
{
sampleResponse.parse(response);
}
}
else
{
// Throw no response exception
throw new NoResponseException("No response received for " + method + " operation");
}
}
धन्यवाद यह मेरे लिए ठीक काम करता है। –