Thanks a billion Javier!

Javier Kohen wrote:
El jue, 14-12-2006 a las 23:45 +0200, Schalk Neethling escribió:
Greetings Javier,

If you could send me the skeleton code that would be very helpful. Thanks!

SOAP over HTTP. Feel free to add this to the project's documentation if
you find it useful. It's based on code found inside ServiceClient.
Alternatively, one could modify ServiceClient to allow a whole envelope
to be passed, but I honestly don't know if that would break some design
principle.

Options options = new Options();
options.setTo(new EndpointReference(..)); // TODO Insert the endpoint
address here.
                options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setAction(..); // TODO Fill your SOAPAction here
options.setExceptionToBeThrownOnSOAPFault(true);

try{
        ServiceClient serviceClient = new ServiceClient();
        serviceClient.setOptions(options);
        // TODO Add headers here.
        serviceClient.addHeader(...);

        OperationClient opClient =
serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP);
        MessageContext mc = new MessageContext();

mc.setServiceContext(opClient.getOperationContext().getServiceContext());

        SOAPFactory soapFactory = getSOAPFactory();
        SOAPEnvelope envelope = soapFactory.getDefaultEnvelope();
        SOAPBody body = envelope.getBody();
        // TODO Add the body's children here
        body.addChild(..);

        serviceClient.addHeadersToEnvelope(envelope);
        mc.setEnvelope(envelope);
        opClient.addMessageContext(mc);
//      opClient.setCallback(new Callback() {
//              @Override
//              public void onComplete(AsyncResult result) {
//                      System.out.println(result);
//              }
//
//              @Override
//              public void onError(Exception e) {
//                      userCallback.failed(e);
//              }
//      });
//      opClient.execute(false); // Async. invocation
        opClient.execute(true); // Blocking invocation
        MessageContext response =
opClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
} catch (AxisFault f) {
        // TODO handle faults here
}

Javier Kohen wrote:
El jue, 14-12-2006 a las 23:09 +0200, Schalk Neethling escribió:
Hi there everyone,

My apologies beforehand for the large amount of code etc. I am new to Axis2 and I am currently implementing a web service. All is going well except when executing the code below I get the following error:

INFO - [org.apache.commons.httpclient.HttpMethodDirector] - I/O exception (org.apache.axis2.AxisFault) caught when processing request: Can not output XML declaration, after other output has already been done.; nested exception is: javax.xml.stream.XMLStreamException: Can not output XML declaration, after other output has already been done.
I've seen this just yesterday myself.

            SOAPBody body = factory.createSOAPBody(envelope);
            OMElement send = factory.createOMElement("Send", ns);
[ Lots of code removed. ]
            body.addChild(send);
            ServiceClient sender = new ServiceClient();
            sender.setOptions(options);
            OMElement result = sender.sendReceive(envelope);
The solution is to pass sendReceive the send element directly; don't
pass it the envelope and body elements. SendReceive ends up
unconditionally wrapping the supplied OMElement within a body element.
Note that you can still set headers this way, by means of the
ServiceClient instance.

In my case, I needed to add two elements to the body, so I had to create
the whole envelope and use the OperationClient interface instead to run
the operation. I can give you skeleton code to do that, in case you need
it, it's only slightly more complex than the above.

Greetings,

--
Kind Regards
Schalk Neethling
Developer.President
AlliedBridge
Landlines
Tel: +27125468436
Fax: +21(0)865122050

Web
email:[EMAIL PROTECTED]
Global: www.alliedbridge.com

Messenger
Yahoo!: v_olume4
AOL: v0lume4
MSN: [EMAIL PROTECTED]

We support OpenSource and Standards
OSI - http://www.opensource.org/
Get Firefox!- The browser reloaded - http://www.mozilla.org/products/firefox/
The information transmitted is intended solely for the individual or entity to 
which it is addressed and may contain confidential and/or privileged material. 
Any review, retransmission, dissemination or other use of or taking action in 
reliance upon this information by persons or entities other than the intended 
recipient is prohibited. If you have received this email in error, please 
contact the sender and please delete all traces of this material from all 
devices.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to