Popular Posts
jQuery : post/get using data() as param object <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html... android.intent.action.SCREEN_ON & android.intent.action.SCREEN_OFF First, I've tried create a receiver to receive screen on/off and register receiver on AndroidManifest.xml like below, but unfortunately ... runas RUNAS 使用方法: RUNAS [ [/noprofile | /profile] [/env] [/netonly] ] /user: program RUNAS [ [/noprofile | /profile] [/env] [/netonly] ...
Blog Archive
Stats
ksoap sample
soap 1.1
POST /WebServiceForTest.asmx HTTP/1.1
Host: brucetsai.test
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/Concat"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <AuthHeader xmlns="http://tempuri.org/">
      <Token1>string</Token1>
    </AuthHeader>
  </soap:Header>
  <soap:Body>
    <Concat xmlns="http://tempuri.org/">
      <key>string</key>
      <value>string</value>
    </Concat>
  </soap:Body>
</soap:Envelope>
soap 1.2
POST /WebServiceForTest.asmx HTTP/1.1
Host: brucetsai.test
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
  <soap12:Header>
    <AuthHeader xmlns="http://tempuri.org/">
      <Token1>string</Token1>
    </AuthHeader>
  </soap12:Header>
  <soap12:Body>
    <Concat xmlns="http://tempuri.org/">
      <key>string</key>
      <value>string</value>
    </Concat>
  </soap12:Body>
</soap12:Envelope>
Java code :
import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.kxml2.kdom.Element;
import org.xmlpull.v1.XmlPullParserException;

public class TestKSOAP {

    public static void main(String[] args) throws IOException, XmlPullParserException {
        String namespace = "http://tempuri.org/";
        String wsdl = "http://brucetsai.test/WebServiceForTest.asmx?WSDL";
        String method = "Concat";
        String soapAction = "http://tempuri.org/Concat";

        SoapObject soap = new SoapObject(namespace, method);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        
        Element[] headers = new Element[1];
        
        Element AuthHeader = new Element();
        AuthHeader.setName("AuthHeader");
        AuthHeader.setNamespace(namespace);
        
        Element element = new Element();
        element.setName("Token1");
        element.setNamespace(namespace);        
        element.addChild(Element.TEXT, "value of token1");        
        AuthHeader.addChild(Element.ELEMENT, element);
        
        headers[0] = AuthHeader;
        
        soap.addProperty("key", "keyValue");
        soap.addProperty("value", "values");
        
        envelope.setOutputSoapObject(soap);
        envelope.headerOut = headers;
        envelope.bodyOut = soap;
        
        
        HttpTransportSE transport = new HttpTransportSE(wsdl);
        transport.call(soapAction, envelope);
        
        System.out.println(envelope.getResponse());
    }
}