2011-11-14 43 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問題有用的人......

乾杯