Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

fellix

Webservice ASP.NET e J2ME

Recommended Posts

Seguiten pessoa baixei o Ksoap pra fazer o parser e pegar o valor do XML do Web Service.

o WebService faz uma consulta em uma banco de dados e retorna o valor de acordo com o nome a tabela contem 2 campos, Id, e Nome, as consultas são feitas pelo nome

 

Eu tentei utilizar o soap 1.1, nem notei diferença do 1.1 rpo 1.2 ai vai o soap retornado pelo WebService

 

Soap de Entrada a tag <name> contem o que vai ser pesquisado

 

POST /AcessoBanco/Service.asmx HTTP/1.1Host: localhostContent-Type: text/xml; charset=utf-8Content-Length: lengthSOAPAction: "http://consult.org/Consulta"<?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:Body>	<Consulta xmlns="http://consult.org/">	  <name>string</name>	</Consulta>  </soap:Body></soap:Envelope>

Soap de retorno

 

HTTP/1.1 200 OKContent-Type: text/xml; charset=utf-8Content-Length: length<?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:Body>	<ConsultaResponse xmlns="http://consult.org/">	  <ConsultaResult>string</ConsultaResult>	</ConsultaResponse>  </soap:Body></soap:Envelope>

No WebService funcionou perfeitamente essa consulta (o Banco é o MySql)

 

agora o cógido foi implementado no NetBeans então uma boa parte do código nem fui eu que fiz, é do proprio netbeans, não liguem para alguns codigos extranhos que não são u tilizados fiz vários testes ai vejam o código

 

/* * Consulta.java * * Created on 17 de Outubro de 2007, 14:16 */import java.io.*;import javax.microedition.midlet.*;import javax.microedition.lcdui.*;import org.ksoap.*;import org.kobjects.serialization.*;import org.kxml.*;import org.kxml.io.*;import org.kxml.parser.*;import org.ksoap.transport.HttpTransport;/** * * @author felix */public class Consulta extends MIDlet implements CommandListener {		/** Creates a new instance of Consulta */	public Consulta() {		//  initialize();	}	private String soapResp =			"<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:Body>" +			" <ConsultaResponse xmlns=\"http://consult.org/\">"'>http://consult.org/\">" +			" <ConsultaResult>string</ConsultaResult>"+			"</ConsultaResponse>"+			" </soap:Body>" +			"</soap:Envelope>";		public String setSoapMsg( String name ){				String soap =				"<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:Body>" +				" <Consulta xmlns=\"http://consult.org/\" xsi:type=\"xsd:string>" +				"  <name> " + name + "</name>" +				" </Consulta>"+				"</soap:Body>" +				"</soap:Envelope>";								return soap;			}		public String RespMsg() throws Exception {				ByteArrayInputStream bis = new ByteArrayInputStream(soapResp.getBytes());		InputStreamReader reader = new InputStreamReader(bis);		XmlParser xp = new XmlParser(reader);				SoapEnvelope envelope = new SoapEnvelope(new ClassMap(Soap.VER11));		envelope.parse(xp);				return (String) envelope.getResult();			}		 private Form form1;					 	 private TextField tfName;	 private StringItem strResult;	 private Command okCommand1;	 private Command exitCommand1;				   	 					 	 /** Called by the system to indicate that a command has been invoked on a particular displayable.					  	  * @param command the Command that ws invoked	  * @param displayable the Displayable on which the command was invoked	  */	 public void commandAction(Command command, Displayable displayable) {							 // Insert global pre-action code here		 if (displayable == form1) {					 			 if (command == exitCommand1) {				   				 // Insert pre-action code here				 				exitMIDlet();					   				// Insert post-action code here			 } else if (command == okCommand1) {					 				 				 String busca = tfName.getString();				 setSoapMsg(busca);				 try {					 strResult.setText( RespMsg() );				 } catch (Exception ex) {					 ex.printStackTrace();				 }				 				 					// Do nothing					   				 // Insert post-action code here			 }					  		 }							 // Insert global post-action code here}				   	 	 /** This method initializes UI of the application.							  */	 private void initialize() {					  		 // Insert pre-init code here		 getDisplay().setCurrent(get_form1());					  		 // Insert post-init code here	 }					 	 	 /**	  * This method should return an instance of the display.	  */	public Display getDisplay() {						 		return Display.getDisplay(this);	}								/**	 * This method should exit the midlet.	 */	public void exitMIDlet() {						 		getDisplay().setCurrent(null);		destroyApp(true);		notifyDestroyed();	}								/** This method returns instance for form1 component and should be called instead of accessing form1 field directly.							 * @return Instance for form1 component	 */	public Form get_form1() {		if (form1 == null) {					  			// Insert pre-init code here			form1 = new Form(null, new Item[] {					   				get_tfName(),				get_strResult()			});			form1.addCommand(get_okCommand1());			form1.addCommand(get_exitCommand1());			form1.setCommandListener(this);					 			// Insert post-init code here		}					  		return form1;	}							/** This method returns instance for tfName component and should be called instead of accessing tfName field directly.							 * @return Instance for tfName component	 */	public TextField get_tfName() {		if (tfName == null) {					  			// Insert pre-init code here			tfName = new TextField("Nome:", "", 120, TextField.ANY);					  			// Insert post-init code here		}					  		return tfName;	}							/** This method returns instance for strResult component and should be called instead of accessing strResult field directly.							 * @return Instance for strResult component	 */	public StringItem get_strResult() {		if (strResult == null) {					  			// Insert pre-init code here			strResult = new StringItem("Resultado", "");					  			// Insert post-init code here		}					  		return strResult;	}							/** This method returns instance for okCommand1 component and should be called instead of accessing okCommand1 field directly.							 * @return Instance for okCommand1 component	 */	public Command get_okCommand1() {		if (okCommand1 == null) {					  			// Insert pre-init code here			okCommand1 = new Command("Ok", Command.OK, 1);					  			// Insert post-init code here		}					  		return okCommand1;	}							/** This method returns instance for exitCommand1 component and should be called instead of accessing exitCommand1 field directly.							 * @return Instance for exitCommand1 component	 */	public Command get_exitCommand1() {		if (exitCommand1 == null) {					  			// Insert pre-init code here			exitCommand1 = new Command("Exit", Command.EXIT, 1);					  			// Insert post-init code here		}					  		return exitCommand1;	}							public void startApp() {				initialize();			}		public void pauseApp() {	}		public void destroyApp(boolean unconditional) {	}	}

o codigo é compilado corretamente sem erros e o aplicativo e executado normalmente qdo eu clico no comando Ok para invocar o Servico aparece um erro

org.kxml.parser.XmlParser$DefaultParserException: Attribute name http:must be followed by '='! @1:86		at org.kxml.parser.XmlParser.parseStartTag(XmlParser.java:390)		at org.kxml.parser.XmlParser.parseSpecial(XmlParser.java:521)		at org.kxml.parser.XmlParser.peek(XmlParser.java:551)		at org.kxml.parser.AbstractXmlParser.skip(AbstractXmlParser.java:127)		at org.ksoap.SoapEnvelope.parseHead(SoapEnvelope.java:81)		at org.ksoap.SoapEnvelope.parse(SoapEnvelope.java:74)		at Consulta.RespMsg(Consulta.java:78)		at Consulta.commandAction(Consulta.java:119)		at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(Display.java:1992)		at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(Display.java:2822)		at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(DefaultEventHandler.java:303		at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(AutomatedEventHandler.java670)		at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(DefaultEventHandler.java:658)

Se alguem entende disso poderia me ajudar? Estou quebrando a cabeça com isso e num axo jeito de resolver isso, já pesquisei e muito, mas não axei isso em lugar nenhum

 

caso queiram ver o ksoap os links são: http://ksoap.objectweb.org/software/downlo...soap-source.zip

http://kxml.objectweb.org/software/downloa...kxml-source.zip

 

espero que possam me ajudar

 

att

Rafael Felix

Compartilhar este post


Link para o post
Compartilhar em outros sites

Amigo o erro ocorre dentro do JAVA ao solicitar o webservice em .NET ??? explique melhor não entendi?? porque você tem 2 webservices em .net e java ??

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.