需要帮助解析android中的soap webservice

时间:2013-07-02 07:48:53

标签: web-services soap wsdl ksoap2 soap-client

如何在android中使用请求信封调用soap服务。我得到SockettimeoutException。 端点:e1jas01.domain.cssus.com:8091/DV910/AddressBookManager?WSDL

//Soap Request...

    <Envelope>
   <Body>
      <getAddressBookV2Element>
        <Entity>
            <EntityId>9</EntityId>
         </Entity>
      </getAddressBookV2Element>
   </Body>
</Envelope>

// Android代码... //在我尝试过的方法之下。

public void callWebservice()
{
    private final String NAMESPACE1 = "http://oracle.e1.bssv.JP010000/";
    private final String URL1 = "https://e1jas01.domain.cssus.com:8091/DV910/AddressBookManager";
    private final String SOAP_ACTION1 = "http://oracle.e1.bssv.JP010000//getAddressBookV2";

    private final String METHOD_NAME1 = "getAddressBookV2";

    SoapObject request = new SoapObject(NAMESPACE1, METHOD_NAME1);
   PropertyInfo weightProp =new PropertyInfo();
    weightProp.name = "arg0";
    weightProp.setValue("9");
    request.addProperty(weightProp);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    // create header
    Element[] header = new Element[1];
    header[0] = new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd","Security");
    header[0].setAttribute(null, "mustUnderstand","1");
    Element usernametoken = new Element().createElement("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "UsernameToken");
    usernametoken.setAttribute(null, "Id", "UsernameToken-1");
    header[0].addChild(Node.ELEMENT,usernametoken);
    Element username = new Element().createElement(null, "n0:Username");
    username.addChild(Node.IGNORABLE_WHITESPACE,"Gowtham");
    usernametoken.addChild(Node.ELEMENT,username);
    Element pass = new Element().createElement(null,"n0:Password");
    pass.setAttribute(null, "Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
    pass.addChild(Node.TEXT, "Gowtham");
    usernametoken.addChild(Node.ELEMENT, pass);
    Element[] body = new Element[1];
    body[0] = new Element().createElement("http://oracle.e1.bssv.JP010000/","getAddressBookV2Element");
    Element EntityNode = new Element().createElement("http://oracle.e1.bssv.JP010000/", "Entity");
    body[0].addChild(Node.ELEMENT,EntityNode);
    Element EntityIdNode = new Element().createElement("http://oracle.e1.bssv.JP010000/", "EntityId");
    EntityIdNode.addChild(Node.IGNORABLE_WHITESPACE,"9");
    EntityNode.addChild(Node.ELEMENT,EntityIdNode);

    // add header to envelope
    envelope.headerOut = header;
    envelope.bodyOut = body;
    envelope.dotNet = false;
    envelope.bodyOut = request;
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    try 
    {
        androidHttpTransport.debug = true;
        androidHttpTransport.call(SOAP_ACTION, envelope);
        SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
        Log.i("myApp", response.toString());
    } 
    catch (SoapFault e)
    {
        e.printStackTrace();
    }
    catch (Exception e) 
    {
        e.printStackTrace();
        Log.d("Exception Generated", ""+e.getMessage());
    }
}

我也尝试在Soap体中添加Propertyinfo而不是Element,但仍然收到Exception。 相同的信封在soapUI工具中运行良好。 可以单独帮助解决这个问题。

谢谢, 的Gowtham。

1 个答案:

答案 0 :(得分:0)

HttpTransportSE.java有多个构造函数。

/**
* Creates instance of HttpTransportSE with set url
*
* @param url
* the destination to POST SOAP data
* @param timeout
* timeout for connection and Read Timeouts (milliseconds)
*/
    public HttpTransportSE(String url, int timeout) {
        super(url, timeout);
    }

替换您的代码:

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL, 60 * 1000); // 60 sec