有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

axis如何通过java调用NetDocuments SOAP API?

我可以通过C#调用NetDocuments SOAP API,如下所示:

// Authenticate to the NetDocuments directory service
ndDir.Directory ndDirectory = new ndDir.Directory();
ndDirectory.CookieContainer = new System.Net.CookieContainer(); // enable cookie handling
ndDirectory.Login( username, password );

// Connect to the NetDocuments storage service
ndStor.storage ndStorage = new ndStor.storage();
ndStorage.CookieContainer = ndDirectory.CookieContainer;        // share cookies with the directory service
XmlNode searchRes = ndStorage.Search( criteria, attrList );

但是,当我使用Axis 1.4通过java调用NetDocuments SOAP API时,收到错误:“没有身份验证会话。身份验证会话已超时或在此调用之前未建立。”

DirectorySoapStub stubDir = new DirectorySoapStub(new URL("https://vault.netvoyage.com/ndApi/directory.asmx"), new DirectoryLocator());
StorageSoapStub stubSto = new StorageSoapStub(new URL("https://vault.netvoyage.com/ndApi/storage.asmx"), new StorageLocator());
stubSto.setMaintainSession(true);
stubDir.login(username, password);

javax.xml.soap.MimeHeaders mhds = stubDir._getCall().getMessageContext().getCurrentMessage().getMimeHeaders();
java.util.Iterator iterator = mhds.getAllHeaders();
while (iterator.hasNext()) {
    javax.xml.soap.MimeHeader mhd = (javax.xml.soap.MimeHeader)iterator.next();
    if ("set-cookie".indexOf(mhd.getName()) >= 0) {
        stubSto._setProperty(mhd.getName(), mhd.getValue());
    }
}

stubSto.search(criteria, attrList);

Java中有类似的CookieContainer吗?如何使用Axis1.4通过java调用NetDocuments SOAP API


共 (1) 个答案

  1. # 1 楼答案

    我意识到这个问题是不久前发布的,但我在过去通过使用NetBeans附带的JAX-RPC插件就能够解决这个问题。我使用的NetBeans版本是v6。8(我认为新版本的NetBeans中不包括JAX-RPC插件,因为JAX-RPC不再广泛使用)。我记得当我尝试使用Axis时,我很难让任何东西正常工作,尽管这很可能是因为我对它不够熟悉

    我记不起所有必要的步骤,但您可以将JAX-RPC插件指向NetDocuments的WSDL,然后为您设置调用API所需的所有类

    要正确处理身份验证,必须将DirectorySoap_存根和StorageSoap_存根类上的SESSION_MAINTAIN_属性设置为true—这将指示它们在登录后维护会话。有关会话维护属性的信息,请参见例如http://docs.oracle.com/cd/E19575-01/821-0177/fxybb/index.html

    此外,当您通过DirectorySoap对象登录时,如果您想使用StorageSoap方法,则需要让StorageSoap对象知道您在DirectorySoap会话中使用的cookie

    为此,我实现了一个javax。xml。rpc。处理程序。处理程序,用于存储DirectorySoap会话中的CookieJar(请求MessageContext上的属性“com.sun.xml.rpc.client.http.CookieJar”),并将该CookieJar设置在StorageSoap会话请求的相同属性上

    希望这对任何有类似SOAP问题的人都有用

    干杯