开发者

How to check if a web service is accessible?

How can I check if any web service is accessible ?

I can see the list of service also I know the method names present in the web service.But I don't know which parameters the method accepts.

Here is the method present in the web service

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

I tried something like http://machine_name/war_name/services/service_name/getChildren?a and got following error

soapenv:Fault>
<faultcode>soapenv:Client</faultcode>
−
<faultstring&开发者_如何学Gogt;
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>   

Is this error mean I am able to access the service but sending wrong arguments ?

Also the service dont have WSDL file.

How can I check whether the service is accessible or how can I find out the exact parameters which are required ?


Well you need to send a request to the service and see if there is a response and there is no exception and thus make sure that the server is running.. Nt comfortable with coding in java but here is the c# excerpt:

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;

There might be easier solutions for java like using the Apache Commons UrlValidator class

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

or use a method like this that gets the response code

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();
}

or try this: http://www.java-tips.org/java-se-tips/java.net/check-if-a-page-exists-2.html

Tell me which one worked for you..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜