Popular Posts
Enable edit option in Shutter in Linux sudo apt-get install libgoo-canvas-perl Reference: How To Fix Disabled Edit Option In Shutter in Linux Mint CORS in Asp.net MVC Web API v2 Step 1. Install cors from NeGet Step 2. Enable cors in config using System; using System.Collections.Generic; using System.Linq; using ... DNS SERVER LIST Google 8.8.8.8 8.8.4.4 TWNIC 192.83.166.11 211.72.210.250 HiNet 168.95.1.1 168.95.192.1 Seednet 北區 DNS (台北, 桃園, 新竹, 宜蘭, 花蓮, 苗栗) 139....
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());
    }
}