You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Tony Liu <li...@gmail.com> on 2008/04/10 06:09:06 UTC

How to retain type info in soap?

Hey,
Can anyone tell me how to retain type infomation of any value in an incoming
soap message in Axis2?
for example, instead of <name>abc</name>, we have <name
type="string">abc</name>.

cheers,

Tony

Re: [U] RE: How to retain type info in soap?

Posted by Tony Liu <li...@gmail.com>.
Hey, thanks for the code.
What I meant is get the types into the incoming messages, so I'm thinking of
any setting at the server side. You don't have to specify types in the
outgoing soap, because I think axis2 will figure them out from wsdl file.

I used to have a "namespace" problem too. The error I got was something like
"need namespace blah blah, found none". If you have a similar problem, I
might be able to help.

On 4/11/08, Higdon, Aaron C Mr CTR USA TRADOC USAAC <
AARON.HIGDON@usaac.army.mil> wrote:
>
> UNCLASSIFIED////
>
>
> I managed to get the types into the message using the ServiceClient, but
> I cannot get the declared namespaces to show up. Here is my code if it
> helps you out:
> public Object invoke(String methodName, Object[] args) throws Exception
> {
>         String response = null;
>         try {
>                 SOAPFactory omFactory =
> OMAbstractFactory.getSOAP11Factory();
>                 SOAPEnvelope envelope = omFactory.getDefaultEnvelope();
>
> envelope.declareNamespace("http://schemas.xmlsoap.org/soap/envelope/",
> "SOAP-ENV");
>
> envelope.declareNamespace("http://schemas.xmlsoap.org/soap/encoding/",
> "SOAP-ENC");
>
> envelope.declareNamespace("http://www.w3.org/2001/XMLSchema", "xsd");
>                 OMNamespace nsXsi =
> envelope.declareNamespace("http://www.w3.org/2001/XMLSchema-instance",
> "xsi");
>                 OMNamespace nsService =
> envelope.declareNamespace("urn:ermservice", "ns1");
>
>                 OMFactory fac = OMAbstractFactory.getOMFactory();
>
>                 OMElement method = fac.createOMElement(methodName,
> nsService);
>                 envelope.getBody().addChild(method);
>
>                 OMElement value = fac.createOMElement("user-String",
> null);
>                 value.addChild(fac.createOMText(this.userName));
>                 value.addAttribute("type", "xsd:string", nsXsi);
>
>                 method.addChild(value);
>
>                 MessageContext msgContext = new MessageContext();
>                 msgContext.setEnvelope(envelope);
>
>                 Options options = new Options();
>                 options.setTo(new EndpointReference(
> this.url.toExternalForm() ));
>
> options.setTransportInProtocol(org.apache.axis2.Constants.TRANSPORT_HTTP
> );
>                 options.setProperty(HTTPConstants.CHUNKED, false);
>
>                 System.out.println(envelope.toString());//correctly
> shows all declared namespaces
>                 ServiceClient sender = new ServiceClient();
>                 sender.setOptions(options);
>
>                 OMElement result = sender.sendReceive(method);
>                 response = result.getFirstElement().getText();
>         } catch (Exception e) {
>             e.printStackTrace();
>         }
>         return response;
>
> }
>
> -----Original Message-----
> From: Tony Liu [mailto:liule410@gmail.com]
> Sent: Thursday, April 10, 2008 12:09 AM
> To: axis-user@ws.apache.org
> Subject: How to retain type info in soap?
>
> Hey,
> Can anyone tell me how to retain type infomation of any value in an
> incoming soap message in Axis2?
> for example, instead of <name>abc</name>, we have <name
> type="string">abc</name>.
>
> cheers,
>
> Tony
>
>
>
> UNCLASSIFIED////
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

[U] RE: How to retain type info in soap?

Posted by "Higdon, Aaron C Mr CTR USA TRADOC USAAC" <AA...@USAAC.ARMY.MIL>.
UNCLASSIFIED////


I managed to get the types into the message using the ServiceClient, but
I cannot get the declared namespaces to show up. Here is my code if it
helps you out:
public Object invoke(String methodName, Object[] args) throws Exception
{
	String response = null;
	try {
		SOAPFactory omFactory =
OMAbstractFactory.getSOAP11Factory();
		SOAPEnvelope envelope = omFactory.getDefaultEnvelope();
	
envelope.declareNamespace("http://schemas.xmlsoap.org/soap/envelope/",
"SOAP-ENV");
	
envelope.declareNamespace("http://schemas.xmlsoap.org/soap/encoding/",
"SOAP-ENC");
	
envelope.declareNamespace("http://www.w3.org/2001/XMLSchema", "xsd");
		OMNamespace nsXsi =
envelope.declareNamespace("http://www.w3.org/2001/XMLSchema-instance",
"xsi");
		OMNamespace nsService =
envelope.declareNamespace("urn:ermservice", "ns1");

		OMFactory fac = OMAbstractFactory.getOMFactory();

		OMElement method = fac.createOMElement(methodName,
nsService);
		envelope.getBody().addChild(method);

		OMElement value = fac.createOMElement("user-String",
null);
		value.addChild(fac.createOMText(this.userName));
		value.addAttribute("type", "xsd:string", nsXsi);

		method.addChild(value);

		MessageContext msgContext = new MessageContext();
		msgContext.setEnvelope(envelope);	

		Options options = new Options();
		options.setTo(new EndpointReference(
this.url.toExternalForm() ));
	
options.setTransportInProtocol(org.apache.axis2.Constants.TRANSPORT_HTTP
);
		options.setProperty(HTTPConstants.CHUNKED, false);

		System.out.println(envelope.toString());//correctly
shows all declared namespaces
		ServiceClient sender = new ServiceClient();
		sender.setOptions(options);

		OMElement result = sender.sendReceive(method);
		response = result.getFirstElement().getText();
	} catch (Exception e) {
	    e.printStackTrace();
	}
	return response;
}

-----Original Message-----
From: Tony Liu [mailto:liule410@gmail.com]
Sent: Thursday, April 10, 2008 12:09 AM
To: axis-user@ws.apache.org
Subject: How to retain type info in soap?

Hey,
Can anyone tell me how to retain type infomation of any value in an
incoming soap message in Axis2?
for example, instead of <name>abc</name>, we have <name
type="string">abc</name>.

cheers,

Tony


UNCLASSIFIED////


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org