Ir para conteúdo
Fórum Script Brasil

AriBitencourt

Membros
  • Total de itens

    2
  • Registro em

  • Última visita

Sobre AriBitencourt

AriBitencourt's Achievements

0

Reputação

  1. muito bom!! e para chamar um método em Java utilizando javascript tem como?
  2. AriBitencourt

    webservice

    Boa tarde! Estou com um pouco de dificuldades para acessar e receber retorno de um webservice utilizando javax.xml.soap, alguém pode me ajudar? segue o código abaixo //import javax.xml.namespace.QName; import javax.xml.namespace.QName; import javax.xml.soap.MessageFactory; import javax.xml.soap.SOAPBody; import javax.xml.soap.SOAPBodyElement; import javax.xml.soap.SOAPConnection; import javax.xml.soap.SOAPConnectionFactory; import javax.xml.soap.SOAPElement; import javax.xml.soap.SOAPEnvelope; import javax.xml.soap.SOAPMessage; import javax.xml.soap.SOAPPart; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; /** * SOAP Client Implementation using SAAJ Api. */ public class teste { /** * Starting point for the SAAJ - SOAP Client Testing */ public static void main(String args[]) { try { // Create SOAP Connection SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance(); SOAPConnection soapConnection = soapConnectionFactory.createConnection(); //Send SOAP Message to SOAP Server String url = "http://172.31.254.188/nAccessWS/nEmbLexmark_01.asmx?wsdl"; SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url); // Process the SOAP Response printSOAPResponse(soapResponse); soapConnection.close(); } catch (Exception e) { System.err.println("Error occurred while sending SOAP Request to Server"); e.printStackTrace(); } } /** * Method used to create the SOAP Request */ private static SOAPMessage createSOAPRequest() throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(); SOAPMessage soapMessage = messageFactory.createMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); // SOAP Envelope SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.getHeader().detachNode(); envelope.addNamespaceDeclaration("xsi", "http://tempuri.org/"); // SOAP Body SOAPBody soapBody = envelope.getBody(); SOAPElement soapBodyElem = soapBody.addChildElement("GetAccountQuotasBalance", "xsi"); soapBodyElem.addNamespaceDeclaration("xsi", "http://tempuri.org/"); soapBodyElem.setAttributeNS("http://tempuri.org/", "GetAccountQuotasBalance", ""); //<---- O ERRO PODE ESTAR AQUI SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("user", "xsi"); SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("domain", "xsi"); soapBodyElem1.addTextNode("nomeusuario"); soapBodyElem2.addTextNode("dominio"); soapMessage.saveChanges(); // Check the input System.out.println("Request SOAP Message = "); soapMessage.writeTo(System.out); System.out.println(); return soapMessage; } /** * Method used to print the SOAP Response */ private static void printSOAPResponse(SOAPMessage soapResponse) throws Exception { TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); Source sourceContent = soapResponse.getSOAPPart().getContent(); System.out.println("\nResponse SOAP Message = "); StreamResult result = new StreamResult(System.out); transformer.transform(sourceContent, result); } } \\XML GERADO= <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://tempuri.org/">'>http://tempuri.org/"> <SOAP-ENV:Body> <xsi:GetAccountQuotasBalance xmlns:ns0="http://tempuri.org/" ns0:GetAccountQuotasBalance=""> <xsi:user>nomeusuario</xsi:user> <xsi:domain>dominio</xsi:domain> </xsi:GetAccountQuotasBalance> </SOAP-ENV:Body> </SOAP-ENV:Envelope> \\XML ESPERADO= <?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> <GetAccountQuotasBalance xmlns="http://tempuri.org/">'>http://tempuri.org/"> <user xmlns="">string</user> <domain xmlns="">string</domain> </GetAccountQuotasBalance> </soap:Body> </soap:Envelope>
×
×
  • Criar Novo...