3728

Set Soap Header ksoap2 android

Question:

First, I apologize for asking a question that is already common here in the SOF.

But I am a beginner and I'm certainly cruel.

I am creating an android application that communicates with a WS. So I can make requests to the WS, I have to add a value to the header of the envelope, but I can not add.

I found some answers about it here in the SOF, however, could not fully understand how it works. Perhaps, my doubts are due to the nodes of the header, which ended up confusing me even more.

One of the answers I found I ended up not helping: "<a href="https://stackoverflow.com/questions/5613675/how-to-set-soap-header-using-ksoap2-android" rel="nofollow">How to set soap header using ksoap2 android</a>"

Below is the XML request that needs to be done:

?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 ValidationSoapHeader xmlns="http://tempuri.org/" DevToken>string/DevToken /ValidationSoapHeader /soap:Header soap:Body ListaCidades xmlns="http://tempuri.org/" / /soap:Body /soap:Envelope

And my code below:

SoapObject request = new SoapObject(ApplicationData.NAMESPACE, ApplicationData.METHOD_NAME_LISTA_CIDADES); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request);

How exactly do I use the envelope.HeaderOut? Is it really necessary to create a helper method to build an Element even having to pass only one parameter (DevToken)?

Thank you for your attention!

Answer1:

Element h = new Element().createElement(NAMESPACE, "AuthHeader"); Element Username = new Element().createElement(NAMESPACE, "Username"); Username.addChild(Node.TEXT, "CBROWN"); h.addChild(Node.ELEMENT, Username); Element wssePassword = new Element().createElement(NAMESPACE, "wssePassword"); wssePassword.addChild(Node.TEXT, "welcome"); h.addChild(Node.ELEMENT, wssePassword); envelope.headerOut = new Element[]{h};

add above code for add header in envelope

Recommend

  • How can I overcome the /AndroidRuntime(331): java.lang.NoClassDefFoundError: javax.microedition.io.C
  • VerifyError in web-service operation using SOAP only in Android 4.2?
  • Sending a sub-segment of an ArrayBuffer over a WebSocket without copying
  • Redirect website to mobile site and from mobile to desktop?
  • Splitting a csv file into panda dataframe by multiple columns
  • How to upload video to Vimeo through their api?
  • How to use data from Mongo and PostgreSQL as in-memory lookup tables?
  • How do I force a browser window to always be on top and in focus
  • Add filename and length parameter to WCF stream when Transfermode = Stream
  • Why do native C++ projects have a TargetFrameworkVersion?
  • I am looking for an algorithm that calculates the power of a number. (x^y), x and y are integers . I
  • wsContext.getMessageContext().get(MessageContext.SERVLET_REQUEST) returns null on Jetty?
  • Testing custom SOAP Headers in ASMX
  • Weird LEFT OUTER JOIN on Includes eager loading of rails 3
  • How to detect left mouse click but not when the click occur on a UI Button component [closed]
  • Arduino making decision according to a packet received from serial port
  • How to make R's read_csv2() recognise the text characters properly
  • Enabling DTD support in Sql Server
  • Undefined references when compiling gSOAP client
  • where do I find the xml.dom python package for the python-2.6.0-8.9.28 and I have a suse/x86_64 vers
  • How to get current document uri in XSLT?
  • Xcode 4 NSLog Macro link in Xcode 3
  • Play WS (2.2.1): post/put large request
  • Is there a javascript serializer for JSON.Net?
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • SSO with signing and signature validation doesn't work
  • Deserializing XML into class C#
  • Symfony2: How to get request parameter
  • Adding custom controls to a full screen movie
  • Is there a mandatory requirement to switch app.yaml?
  • How to include full .NET prerequisite for Wix Burn installer
  • log4net write single file for each call to log.info
  • Getting error when using KSoap library to consume .NET web services
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • reshape alternating columns in less time and using less memory
  • costura.fody for a dll that references another dll
  • How to Embed XSL into XML
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize