users@jax-rpc.java.net

How to generate a soap message Header using DII (Dynamic interfac e invocation)?

From: Oppedal Anita <anita.oppedal_at_TIETOENATOR.COM>
Date: Wed, 07 May 2003 16:44:41 +0200

I want to contact a webservice, that requires the following
soapmessage for input:

<soap-env:Envelope>
        <soap-env:header>
                <RequestHeader>
                        <AuthenticationInfo>
                        </AuthenticationInfo>
                        <UserName></UserName>
                        <SystemInfo>
                                <Version>
                                </Version>
                        </SystemInfo>
                        </ConfigSectionName>
                </RequestHeader>
        </soap-env:header>
        <soap-env:Body>
                <GetUserLoging>
                        <UserName></UserName>
                        <PassWord></PassWord>
                </GetUserLogin>
        </soap-env:Body>
</soap-env:Envelope>

I am using DII, and have succeedes creating the body element
with this class:
*******************
package dynamic;

import javax.xml.rpc.Call;
import javax.xml.rpc.Service;
import javax.xml.rpc.JAXRPCException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.ParameterMode;

public class HelloClient {

    private static String endpoint =
        "http://localhost:8080/dynamic-jaxrpc/dynamic";


    private static String
AUTH_URL="http://alfa/PasLink/AuthenticationWS/AuthenticationWS.asmx";
    private static String
PAT_URL="http://alfa/PasLink/PatientWS/PatientWS.asmx";
    private static String
SOAP_ACTION="http://healthXML.org/PasLink/GetUserLogin";

    private static String USERNAME="usernameValue";

private static String qnameService = "PasLink";
    private static String qnamePort = "PasLinkIF";

    private static String BODY_NAMESPACE_VALUE =
       "http://healthXML.org/PasLink";

    private static String ENCODING_STYLE_PROPERTY =
        "javax.xml.rpc.encodingstyle.namespace.uri";
    private static String NS_XSD =
        "http://www.w3.org/2001/XMLSchema";
    private static String URI_ENCODING =
         "http://schemas.xmlsoap.org/soap/encoding/";

    public static void main(String[] args) {
        try {
            ServiceFactory factory =
                ServiceFactory.newInstance();
            Service service =
                factory.createService(new QName(qnameService));

            QName port = new QName(qnamePort);


            Call call = service.createCall(port);

            call.setTargetEndpointAddress(AUTH_URL);


            call.setProperty(Call.SOAPACTION_USE_PROPERTY,
                new Boolean(true));

            call.setProperty(Call.SOAPACTION_URI_PROPERTY, SOAP_ACTION);

            //Encoding settes til soap sin encoding
            call.setProperty(ENCODING_STYLE_PROPERTY, URI_ENCODING);
            call.setProperty(Call.USERNAME_PROPERTY, USERNAME);

            QName QNAME_TYPE_STRING = new QName(NS_XSD, "string");
            call.setReturnType(QNAME_TYPE_STRING);

            call.setOperationName(new QName(BODY_NAMESPACE_VALUE,
                "GetUserLogin"));
            call.addParameter("UserName", QNAME_TYPE_STRING,
              ParameterMode.IN);
            call.addParameter("PassWord", QNAME_TYPE_STRING,
              ParameterMode.IN);

            String[] params={"Usernamevalue","PaswordValue"};


            String result = (String)call.invoke(params);

            System.out.println(result);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

>>From this I am able to create this message:
POST /PasLink/AuthenticationWS/AuthenticationWS.asmx HTTP/1.1
Content-Type: text/xml; charset="utf-8"
Content-Length: 540
SOAPAction: "http://healthXML.org/PasLink/GetUserLogin"
Authorization: Basic aW5mb214Om51bGw=
User-Agent: Java/1.4.1_02
Host: localhost:8090
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><env:Body><ans
1:GetUserLogin xmlns:ans1="http://healthXML.org/PasLink"><UserName
xsi:type="xsd:string">UserNameValue</UserName><PassWord
xsi:type="xsd:string">PassWordValue</PassWord></ans1:GetUserLogin></env:Body
></env:Envelope>

But unfortunealty I have not found out how to create an soap header element.
The answer I get from the server is:
HTTP/1.1 100 Continue
Server: Microsoft-IIS/5.0
Date: Wed, 07 May 2003 11:47:38 GMT

HTTP/1.1 500 Internal Server Error.
Server: Microsoft-IIS/5.0
Date: Wed, 07 May 2003 11:47:38 GMT
Cache-Control: private
Content-Type: text/xml; charset=utf-8
Content-Length: 343

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <soap:Fault>
      <faultcode>soap:Server</faultcode>
      <faultstring>Server did not find required RequestHeader SOAP header in
the message.</faultstring>
    </soap:Fault>
  </soap:Body>
</soap:Envelope>

I really hope anybody Is able to help me about this!

Yours Sincerely

Anita Oppedal



I am very gratefull if somebody have good examples who explain the
differents, or can refer to good articles about this theme. Do you use
either JAX-RPC and JAXM to the same purpose, or do you combine them it some
solutions?

Thank you.

yours sincerely

Anita Iren Oppedal