0

我正在尝试通过使用 Eclipse 的 BlackBerry Java 插件在字符串中传递请求 xml 来使用 SOAP 响应 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;
}
4

2 回答 2

0

我注意到您没有在请求中包含 SoapAction 标头。

SOAP Web 服务通常有一个固定的 URL,并且使用 SoapAction 标头选择不同的方法。您可以通过在浏览器中打开 WSDL 并检查要调用的方法的格式来检查标头。

一旦您知道要选择哪个操作,请将其设置为常规 http 标头:

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

代码中的另一个问题来源是您使用的旧HttpConnection类需要根据传输类型(MDS、BIS、Wi-Fi 等)向 URL 附加后缀。除非您的目标是 OS 4.5 和更低版本,否则您不需要使用这个遗留类。所以看看ConnectionFactory类,它更容易使用。它从 OS 5.0 开始可用。

于 2012-09-05T16:28:36.180 回答
0

我认为你没有问的主要问题http. getResponseCode()。我认为 BB 在您调用它之前不会进行任何交互。

我也会在真实设备上小心使用此代码。在 BlackBerries 上搜索正确的打开连接。

于 2012-09-05T06:57:32.817 回答