2011-04-04 23 views
7

Web servisim var, bir istemci oluşturmaya çalışıyorum.soap ui code

Aşağıdaki wsdl var:

http://www.cmicdataservices.com/datacenter/service.asmx?wsdl 

Bu kimlik doğrulaması gerektiriyor. WSDL açıklamasına baktığımda, kimlik doğrulama nesnesini kullanan bir yöntem veya argüman olarak kullanıcı adı ve parolaları göremiyorum. Netbeans'i kullanma WSDL için jax-ws kaynakları ürettim. Ancak bundan sonra ne yapacağımı anlayamıyorum.

Soapui'yi kullanma Web servisine bağlanabilir ve tüm yöntemleri çalıştırabilirim. Ama bir kez daha, bu etkileşimi kullanmadan çalıştırılabilecek bir müşteriye dönüştürmek istiyorum.

Sorunum, üretilen bu kodun nasıl kullanıldığını, netbeans.tv'nin kaybolmuş olan bir videosu (netbeans soapui eklentisi video 2) göründüğünü ortaya çıkarmaktadır. Herhangi bir öğreticiden haberi var mı, yoksa bu kodun web servisine nasıl erişebileceğine dair herhangi bir örnek var mı?

yüzden CheckifAuthorized()

SoapUI içinde Running bir yöntemi var ben daha sonra sabun ui bu isteği çalıştırmak ve kimlik doğrulama başarılı olduğunu yanıtı geri alabilirsiniz

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:cmic="http://www.cmicdataservices.com/"> 
    <soap:Header> 
     <cmic:Authentication> 
     <!--Optional:--> 
     <cmic:UserName>username</cmic:UserName> 
     <!--Optional:--> 
     <cmic:Password>password</cmic:Password> 
     </cmic:Authentication> 
    </soap:Header> 
    <soap:Body> 
     <cmic:CheckIfAuthorized/> 
    </soap:Body> 
</soap:Envelope> 

aşağıdaki XML olsun .

package javaapplication7; 

/** 
* 
* @author grant 
*/ 
public class Main { 

    public static void main(String[] args) { 

     Boolean result = checkIfAuthorized(); 
     System.out.println("The result is: " + result); 
    } 

    private static boolean checkIfAuthorized() { 
     javaapplication7.CMICDatacenterService service = new javaapplication7.CMICDatacenterService(); 
     javaapplication7.CMICDatacenterServiceSoap port = service.getCMICDatacenterServiceSoap(); 
     return port.checkIfAuthorized(); 
    } 
} 

Bu, aynı sorun şu hata

run: 
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Server was unable to process request. ---> Object reference not set to an instance of an object. 
     at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178) 
     at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:111) 
     at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108) 
     at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78) 
     at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107) 
     at $Proxy30.checkIfAuthorized(Unknown Source) 
     at javaapplication7.Main.checkIfAuthorized(Main.java:24) 
     at javaapplication7.Main.main(Main.java:17) 
Java Result: 1 

başarısız olur: netbeans ve SoapUI oluşturulacak JAX-WS kod ile

da aşağıdaki bilgisi hizmet için python kullanmaya çalışırken devreye girdi. Java ile gitmeyi seçtiğimden beri, xml'yi ayrıştırırken daha hızlı bir dönüşüme sahip olabileceğimi ve bunun için zaten nesneler oluşturduğum gibi nesneler oluşturduğumu hissettim.

Teşekkür ederiz.

Grant

Sana, hala burada yapabilirsiniz anlamaya istiyorum çünkü bu cevap vermek istemedim, ama sadece aşağıdaki ile elle isteği yazma sonunda. Şimdi bunu bir xml nesnesine dönüştürebilir ve yoluma devam edebilirim, ama soapui'nin bunu daha kolay hale getirdiğini hayal ediyorum. Ne gerçekten anlamıyorum bu talebi oluşturmak ve projeme içine dahil etmek SoapUI nasıl kullanılacağı şudur: koduyla

public class Main { 

    public final static String DEFAULT_SERVER = 
      "http://www.cmicdataservices.com/datacenter/service.asmx"; 
    public final static String SOAP_ACTION = 
      "http://www.cmicdataservices.com/CheckIfAuthorized"; 

    public static void main(String[] args) { 
     String server = DEFAULT_SERVER; 
     String UserName = "Username"; 
     String Password="Password"; 


    try{ 
      URL url = new URL(server); 
      HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 

      connection.setDoOutput(true); 
      connection.setDoInput(true); 
      connection.setRequestMethod("POST"); 
      connection.setRequestProperty("Content-Type", "application/soap+xml; charset=utf-8"); 
      connection.setRequestProperty("Host", "www.cmicdataservices.com"); 
      OutputStream out = connection.getOutputStream(); 
      Writer wout = new OutputStreamWriter(out); 
      // Uncomment the following and comment out the previous two lines to see your xml 
      //BufferedWriter wout = new BufferedWriter(new FileWriter("/tmp/testXML.xml")); 

      //Start writing soap request - Envelope 
      wout.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"); 
      wout.write("<soap12:Envelope "); 
      wout.write("xmlns:xsi="); 
      wout.write("'http://www.w3.org/2001/XMLSchema-instance' "); 
      wout.write("xmlns:xsd="); 
      wout.write("'http://www.w3.org/2001/XMLSchema' "); 
      wout.write("xmlns:soap12="); 
      wout.write("'http://www.w3.org/2003/05/soap-envelope'>\r\n"); 

      //Soap request header start 
      wout.write("<soap12:Header>\r\n"); 

      //Start writing soap request - Authentication 
      wout.write("<Authentication xmlns="); 
      wout.write("'http://www.cmicdataservices.com/'>\r\n"); 
      wout.write("<UserName>" + UserName + "</UserName>\r\n"); 
      wout.write("<Password>" + Password + "</Password>\r\n"); 
      // End Authentication 
      wout.write("</Authentication>\r\n"); 

      //End the header 
      wout.write("</soap12:Header>\r\n"); 

      //Start writing the body 
      wout.write("<soap12:Body>"); 
      wout.write("<GetCurrentDataVer1 xmlns="); 
      wout.write("'http://www.cmicdataservices.com/' />\r\n"); 
      // End the Body 
      wout.write("</soap12:Body>\r\n"); 

      // End the Envelope 
      wout.write("</soap12:Envelope>\r\n"); 

      wout.flush(); 
      wout.close(); 


      //BufferedWriter fout = new BufferedWriter(new FileWriter("/tmp/testXMLResponse.xml")); 
      InputStream in = connection.getInputStream(); 
      createFile(in, "/tmp/testXMLResponse.xml"); 
    } 
    catch (IOException e) { 
     System.err.println(e); 
    } 
    } 

    public static void createFile(InputStream io, String fileName) throws IOException { 
     FileOutputStream fout = new FileOutputStream(fileName); 
     byte[] buf = new byte[256]; 
     int read = 0; 
     while ((read = io.read(buf)) != -1){ 
      fout.write(buf, 0, read); 
     } 
    } 

cevap

3

sorun SABUN başlığındaki Kimlik eleman eksikliğidir. WSDL bir göz atın, her zaman orada olmalı: CheckIfAuthorized istekte hiçbir Doğrulama öğe olduğunda,

<wsdl:operation name="CheckIfAuthorized"> 
    <soap:operation soapAction="http://www.cmicdataservices.com/CheckIfAuthorized" style="document"/> 
    <wsdl:input> 
     <soap:body use="literal"/> 
     <soap:header message="tns:CheckIfAuthorizedAuthentication" part="Authentication" use="literal"/> 
    </wsdl:input> 
    <wsdl:output> 
     <soap:body use="literal"/> 
    </wsdl:output> 
</wsdl:operation> 

Sunucu yanlış olduğu için XML dışında başarısız olur. İşte Python'daki örnek bir istemci, problemi çözme fikrini göstermek için, bunu Java'ya dönüştürmeniz için bir problem değil.

from suds.client import Client 

client = Client("http://www.cmicdataservices.com/datacenter/service.asmx?wsdl") 
auth = client.factory.create('Authentication') 
auth.UserName = "username" 
auth.Password = "password" 
client.set_options(soapheaders=auth) 
client.service.CheckIfAuthorized() 
+0

@grantk bu bizim sorunu çözdünüz? – tgkprog

İlgili konular