2011-08-10 44 views
0

如何檢查是否有任何Web服務可訪問?
我可以看到服務列表,我也知道Web服務中存在的方法名稱。但我不知道該方法接受哪些參數。
這是存在於Web服務如何檢查Web服務是否可訪問?

public OMElement getChildren(OMElement paramOMElement) 
    { 
    Object localObject2 = paramOMElement.toString(); 
    // Some other stuff 
    } 

我想是這樣http://machine_name/war_name/services/service_name/getChildren?a 的方法得到了以下錯誤

soapenv:Fault> 
<faultcode>soapenv:Client</faultcode> 
− 
<faultstring> 
Umarshaller error: Error during unmarshall <getChildren><a></a></getChildren>; nested exception is: 
    edu.harvard.i2b2.common.exception.I2B2Exception: Umarshaller error: Error during unmarshall <getChildren><a></a></getChildren>; nested exception is: 
    org.apache.axis2.AxisFault: Umarshaller error: Error during unmarshall <getChildren><a></a></getChildren>; nested exception is: 
    edu.harvard.i2b2.common.exception.I2B2Exception: Umarshaller error: Error during unmarshall <getChildren><a></a></getChildren> 
</faultstring> 
<detail/> 
</soapenv:Fault> 

這是錯誤的意思是我能夠訪問該服務,但發送錯誤的參數?
服務也沒有WSDL文件。
如何檢查服務是否可以訪問,或者如何找出所需的確切參數?

回答

3

那麼你需要發送到服務的請求,看看是否有響應,並沒有什麼異常,從而確保服務器正在運行.. Nt個舒服的Java代碼,但這裏是C#摘錄:

function bool CheckIfServiceIsAlive(string url) 
{ 
var isServiceUrlAlive= false; 
      var req = WebRequest.Create(url); 
      if (!string.IsNullOrEmpty(proxyServer)) 
      { 
       var proxy = new WebProxy(proxyServer, 8080) { Credentials = req.Credentials }; //if you need to use a proxy 
       WebRequest.DefaultWebProxy = proxy; 
       req.Proxy = proxy; 
      } 
      else 
      { 
       req.Proxy = new WebProxy(); 
      } 
      try 
      { 
       var response = (HttpWebResponse)req.GetResponse(); 
       isServiceUrlAlive= true; 
      } 
      catch (WebException) { } 

      return isServiceUrlAlive; 

有可能會像使用Apache Commons UrlValidator

UrlValidator urlValidator = new UrlValidator(); 
urlValidator.isValid("http://<your service url>"); 

或使用這樣的方法獲得響應代碼的Java更容易解決方案

public static int getResponseCode(String urlString) throws MalformedURLException, IOException { 
    URL u = new URL(urlString); 
    HttpURLConnection huc = (HttpURLConnection) u.openConnection(); 
    huc.setRequestMethod("GET"); 
    huc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)"); 
    huc.connect(); 
    return huc.getResponseCode(); 
} 

或試試這個:http://www.java-tips.org/java-se-tips/java.net/check-if-a-page-exists-2.html

告訴我,哪一個爲你工作..

+0

感謝您的解決方案。你可以讓代碼更簡單,因爲我知道方法的確切字符串,但不知道參數(我對c#不太友好)。 – xyz

+0

感謝您提供Java解決方案:) – xyz

相關問題