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