Viewed   84 times

Is there available any tool for PHP which can be used to generate code for consuming a web service based on its WSDL? Something comparable to clicking "Add Web Reference" in Visual Studio or the Eclipse plugin which does the same thing for Java.

 Answers

5

I've had great success with wsdl2php. It will automatically create wrapper classes for all objects and methods used in your web service.

Thursday, October 27, 2022
4

I use this function to get data from a web service.

Private Function HttpGetRequest(url As String) As DOMDocument
    Dim req As XMLHTTP60
    Set req = New XMLHTTP60
    req.Open "GET", url, False
    req.send ""

    Dim resp As DOMDocument
    If req.responseText <> vbNullString Then
        Set resp = New DOMDocument60
        resp.loadXML req.responseText
    Else
        Set resp = req.responseXML
    End If
    Set HttpGetRequest = resp
End Function
Thursday, December 8, 2022
 
bram
 
1

ASP.NET Web Service Application project template is not available for .Net framework 4.0, however, available for .Net Framework 3.5.

If you're building your application on .net framework 4.0, You can use WCF Service Application as ASMX in legacy. Please note that you'd need to enable AspNetCompatibilityMode to access HttpContext objects.

If you still want to use ASMX, choose ASP.NET Empty Web application and then you can add ASMX files to the project.

Monday, September 26, 2022
 
1
  1. Create Empty ASP.NET Project
  2. Add Web Service(asmx) to your project
Sunday, September 25, 2022
 
zhz
 
zhz
3

Since you only care about consuming a webservice, I assume you already know how to send data from the web server. Do you use JSON or XML, or any other kind of data format?

I myself prefer JSON, especially for Android. Your question still lacks some vital information.

I personally use apache-mime4j and httpmime-4.0.1 libraries for web services.

With these libraries I use the following code

public void get(String url) {
    HttpResponse httpResponse = null;
    InputStream _inStream = null;
    HttpClient _client = null;
    try {

        _client = new DefaultHttpClient(_clientConnectionManager, _httpParams);
        HttpGet get = new HttpGet(url);

        httpResponse = _client.execute(get, _httpContext);
        this.setResponseCode(httpResponse.getStatusLine().getStatusCode());

        HttpEntity entity = httpResponse.getEntity();
        if(entity != null) {
            _inStream = entity.getContent();
            this.setStringResponse(IOUtility.convertStreamToString(_inStream));
            _inStream.close();
            Log.i(TAG, getStringResponse());
        }
    } catch(ClientProtocolException e) {
        e.printStackTrace();
    } catch(IOException e) {
        e.printStackTrace();
    } finally {
        try {
            _inStream.close();
        } catch (Exception ignore) {}
    }
}

I make a request via _client.execute([method], [extra optional params]) The result from the request is put in a HttpResponse object.

From this object you can get the status code and the entity containing the result. From the entity I take the content. The content would in my case be the actualy JSON string. You retrieve this as an InputStream, convert the stream to a string and do whatever you want with it.

For example

JSONArray result = new JSONArray(_webService.getStringResponse()); //getStringResponse is a custom getter/setter to retrieve the string converted from an inputstream in my WebService class.

Depending on how you build your JSON. mine is nested deeply with objects in the array etc. But handling this is basic looping.

JSONObject objectInResult = result.getJSONObject(count);//count would be decided by a while or for loop for example.

You can extract data from the current JSON object in this case like:

objectInResult.getString("name"); //assume the json object has a key-value pair that has name as a key.
Thursday, August 11, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :