2012-06-07 113 views
3

我正在編碼使用Netbeans在Java中使用Sharepoint 2010 Web服務。我可以使用提供的嚮導從WSDL創建Web服務客戶端。當我把下面的代碼我得到的Microsoft.SharePoint.SoapServer.SoapServerExceptionSharepoint Web服務引發Microsoft.SharePoint.SoapServer.SoapServerException

import java.net.Authenticator; 
import java.net.URL; 

import javax.xml.namespace.QName; 
import javax.xml.ws.BindingProvider; 

import proxy.webs.GetWebCollectionResponse; 
import proxy.webs.GetWebResponse; 
import proxy.webs.Webs; 
import proxy.webs.WebsSoap; 

public class AccessLists { 

    public static void main(String[] args) throws Exception { 
     String username = "domain\\Administrator"; 
     char[] password = "password".toCharArray(); 
     NtlmAuthenticator ntlmAuth = new NtlmAuthenticator(username, password); 
     Authenticator.setDefault(ntlmAuth); 

     Webs websService = new Webs(new URL("http://servername:7766/_vti_bin/Webs.asmx?wsdl")); 
     WebsSoap webPort = websService.getWebsSoap(); 
     GetWebResponse.GetWebResult webRes = webPort.getWeb("http://servername/sites/Test1"); 
     System.out.println(webRes); 
    } 
} 

網站http://servername/sites/Test1存在,我可以在瀏覽器中打開它。

更新1:類似的事情發生了C#代碼,這是我在同一臺機器上運行,截至2010年的Sharepoint:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 

namespace ConsoleApplication1 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      Webs webService = new Webs(); 
      webService.Credentials = System.Net.CredentialCache.DefaultCredentials; 
      Object o = webService.GetWeb("http://servername/sites/Test1"); 
      Console.WriteLine(o.ToString()); 
     } 
    } 
} 

我想這是有問題的設置,而不是用代碼。

回答

0

我對Web服務使用了錯誤的端點。對於Sharepoint網站http://servername/sites/Test1,終點也應該是http://servername/sites/Test1/_vti_bin/Webs.asmx?wsdl