2011-11-14 47 views
1

我可以用C#作为以下称NetDocuments SOAP API:如何通过java调用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); 

然而,当我打电话NetDocuments SOAP API通过用java轴1.4,我收到错误:“无验证会话验证会话超时或在这次电话会议之前并没有成立。“

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?我如何使用Axis 1.4通过Java调用NetDocuments SOAP API?

回答

0

我意识到这个问题是前一段时间发布的,但通过使用NetBeans附带的JAX-RPC插件,我能够在过去得到这个工作。我使用的NetBeans版本是v6.8(我认为JAX-RPC插件不包含在较新版本的NetBeans中,因为JAX-RPC不再被广泛使用)。我记得在尝试使用Axis时努力工作,尽管这很可能是因为我对它不熟悉。

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

要正确处理身份验证,需要将DirectorySoap_Stub和StorageSoap_Stub类上的SESSION_MAINTAIN_PROPERTY设置为true - 这将指示他们在登录后维护会话。 http://docs.oracle.com/cd/E19575-01/821-0177/fxybb/index.html对SESSION_MAINTAIN_PROPERTY

信息此外,当您通过DirectorySoap对象登录,如果再要使用StorageSoap的方法,你需要让StorageSoap对象知道你正在使用的DirectorySoap会话cookie的。

为此,我实现了一个javax.xml.rpc.handler.Handler,它存储来自DirectorySoap会话(请求MessageContext上的属性“com.sun.xml.rpc.client.http.CookieJar”)的CookieJar和将该CookieJar设置为StorageSoap会话请求的相同属性。

希望这是与类似的SOAP问题有用的人......

干杯