18. Februar 2011

ASP.NET: Consuming a PHP WSDL SOAP Webservice

After starting Visual Studio we create a new Visual Basic ASP.NET Web Application project:


After it opens up we right-click on the project name in the "Solution Explorer" and choose "Add Web Reference..."


Now we can enter the URL of the WSDL file 'http://customer-ws.tld/customer-ws_Customers.wsdl' and press 'Enter'. Visual Studio fetches all the information provided by the xml file and shows up all the data:


We enter a "Web reference name" (I choose 'WSDLWebService') and click on "Add Reference". Now we can see the entered Web Reference in the "Solution Explorer":


Now we right-click the Web Reference called "WSDLWebService" and choose "View in Object Window":


We can see here that Visual Studio has created all the objects and methods that the WSDL file announced.

So we go to the "Code Editor" of our Default.aspx by right-clicking the file in the "Solution Explorer" and enter the following lines:



Public Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim CallWebservice As New WSDLWebService.customer-ws_Customers

        Dim Cache As System.Net.CredentialCache = New System.Net.CredentialCache

        Dim vUserId As String
        vUserId = "1889941"

        Dim vCustomer() As WSDLWebService.Customer
        vCustomer = CallWebservice.getCustomers()

        Label1.Text = vCustomer.length

    End Sub

End Class


I have added a Label with the ID "Label1" with the "Designer" and the Toolbar to the Default-Page:



Now we can press debug and the Internet Explorer should pop up and display in the Label1 field the amount of Customers returned by the WebService.

More information about SOAP Webservices:
PHP : SOAP: Creating and Consuming a WSDL Web-Service

Keine Kommentare:

Kommentar veröffentlichen