2013-10-26 4 views
2

Я новичок в клиенте SOAP webservice и получаю ошибки при создании клиента.SOAP Webservice Client в Java

пожалуйста, помогите мне решить эту

//This is request that has to be send using SOAP Envelope 

POST /DISWebService/DISWebService.asmx HTTP/1.1 
Host: 192.168.2.119 
Content-Type: application/soap+xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
    <LoginSystem xmlns="http://tempuri.org/"> 
     <username>string</username> 
     <password>string</password> 
    </LoginSystem> 
    </soap12:Body> 
</soap12:Envelope> 

Java Code

public static void main(String args[]) { 
    try { 
     // Create SOAP Connection 
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory  .newInstance(); 
    SOAPConnection soapConnection = soapConnectionFactory 
        .createConnection(); 

      String url = "http://192.168.2.119/VISWebService/VISWebService.asmx"; 
      // String url = 
      // "http://192.168.2.119/DISWebService/DISWebService.asmx?op=LoginSystem"; 

      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(); 
     } 
} 

private static SOAPMessage createSOAPRequest() throws Exception { 
     MessageFactory messageFactory = MessageFactory.newInstance(); 
     SOAPMessage soapMessage = messageFactory.createMessage(); 
     SOAPPart soapPart = soapMessage.getSOAPPart(); 


     String serverURI = "http://192.168.2.119/DISWebService/DISWebService.asmx"; 

     // SOAP Envelope 
     SOAPEnvelope envelope = soapPart.getEnvelope(); 

     // SOAP Body 
     SOAPBody soapBody = envelope.getBody(); 

     SOAPElement soapBodyElem = soapBody.addChildElement("LoginSystem"); 

     SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("username"); 
     soapBodyElem1.addTextNode("Chirendu"); 

     SOAPElement soapBodyElem2 = soapBodyElem.addChildElement("password"); 
     soapBodyElem2.addTextNode("verve12*"); 

     MimeHeaders headers = soapMessage.getMimeHeaders(); 
     headers.addHeader("SOAPAction", serverURI); 

     soapMessage.saveChanges(); 

     /* Print the request message */ 
     System.out.print("Request SOAP Message = "); 
     soapMessage.writeTo(System.out); 
     System.out.println(); 

     return soapMessage; 
    } 

Пожалуйста, помогите мне создать клиента.

+0

'soapConnection.call (createSOAPRequest(), url); 'это сделает SOAP-запрос указанному URL-адресу. Для чего вам нужен клиент? – Newbie

+0

Я хочу использовать данный веб-сервис и нуждаюсь в том, чтобы его показывать в UI. –

+0

Если я правильно понимаю, ваш клиент Web-сервиса отлично работает, и вы просите графический интерфейс, правильно? – home

ответ

3

Я предлагаю отладки в 2 шагах

1) Используйте soapUI и проверить, является ли ваш ответ в ближайшем или не

2) Используйте рабочий пример я использовал от mykong

+0

с использованием SOAPUI для начинающих было бы легко узнать, сравнив запрос SOAP –