0

我試圖通過在Eclipse中使用BlackBerry Java插件在字符串中傳遞請求xml來使用SOAP響應xml。過去兩天我一直在尋找解決方法。黑莓 - 沒有得到肥皂響應xml

我附上了下面的示例代碼。

public String CheckXml() 
{ 
    final String requestXml="<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\"><header xmlns=\"http://schemas.cordys.com/General/1.0/\"></header><SOAP:Body><authenticateAgainstOID xmlns=\"http://schemas.cordys.com/OIDAuthentication\"><stringParam>HEMANTS_MUM013</stringParam><stringParam1>TATA2012</stringParam1></authenticateAgainstOID></SOAP:Body></SOAP:Envelope>"; 

    final String HOST_ADDRESS = "http://xyz.com/cordys/com.eibus.web.soap.Gateway.wcp?organization=o=B2C,cn=cordys,cn=cbop,o=tatamotors.com&SAMLart=MDFn+8e5dRDaRMRIwMY7nI84eEccbx+lIiV0VhsOQ7u+SKG6n5+WNB58"; 
    String result=""; 
    try { 
     HttpConnection url=(HttpConnection)Connector.open(HOST_ADDRESS); 
     url.setRequestProperty("Content-Type", "text/xml"); 
     url.setRequestMethod(HttpConnection.GET); 
     OutputStreamWriter writer=new OutputStreamWriter(url.openOutputStream()); 

     writer.write(requestXml); 
     writer.flush(); 
     writer.close(); 
     StringBuffer buffer1=new StringBuffer(); 

     InputStreamReader reader=new InputStreamReader(url.openInputStream()); 
     StringBuffer buffer=new StringBuffer(); 
     char[] cbuf=new char[2048]; 
     int num; 

     while (-1 != (num = reader.read(cbuf))) { 
      buffer.append(cbuf, 0, num); 
     } 

     String result1 = buffer.toString(); 
    } catch (Exception e) { 
     System.out.println(e); 
    } 
    return result; 
} 

回答

0

我想,你是不是問http. getResponseCode()的主要問題。我認爲BB在你打電話之前不會進行任何互動。

我也會在真實設備上使用這段代碼。在黑莓上搜索正確的打開連接。

+0

我試圖也用於檢查http連接,我在這裏發佈的代碼,如果(url.getResponseCode()== HttpConnection.HTTP_OK) \t \t { \t \t \t的InputStream的inputStream = url.openInputStream() ; \t \t \t buffer.append(IOUtilities.streamToBytes(inputStream)); \t \t \t result = buffer.toString(); \t \t \t \t \t}但它不適合我 – Pramodhini

+0

你得到了什麼?有一些例外?也許你需要設置一些接受標題。你可以嗅探桌面客戶端,並檢查它發送到服務器的標題/也許你需要改變方法從GET到POST。 –

+0

嗨改變和檢查後,仍然現在得到相同的錯誤,像類沒有找到inputstreamreader線附近。 – Pramodhini

0

我注意到你沒有在請求中包含SoapAction頭。

SOAP Web服務通常具有固定的URL,並且使用SoapAction標頭選擇不同的方法。您可以通過在瀏覽器中打開WSDL並檢查要調用的方法的格式來檢查標題。

一旦你知道選擇哪個動作,將其設置爲一個普通的HTTP標頭:

url.setRequestProperty("SOAPAction", <your action here>); 

代碼中的另外的一個問題是,您使用的是舊HttpConnection類,需要追加一個後綴爲URL取決於傳輸類型(MDS,BIS,Wi-Fi等)。除非您的操作系統是OS 4.5或更低版本,否則不需要使用此舊版本。所以看看ConnectionFactory這個類,它更容易使用。它從OS 5.0起可用。

+0

嗨,我已經嘗試了所有的因素,甚至沒有得到積極的結果,以保持下一步。而且這不是一個wsdl服務format.passing請求xml,響應xml應該以字符串格式 – Pramodhini

+0

它在哪一行失敗?拋出什麼類型的異常? –

+0

通過檢查中斷點,它落在inputstreamreader之後,它將源文件找不到.wat模擬器用於5個OS版本。 – Pramodhini