Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to call a webservice from .Net

Former Member
0 Kudos

HI,

How do i call a SAP webservice from .Net application.

Thanks in advance,

Anoop

1 ACCEPTED SOLUTION

rudi_aubermann2
Explorer
0 Kudos

Hi,

assuming that the SAP-side is covered, you should be able to obtain a WSDL-File from your SAP-Application Server. The address of the WSDL-File is somehow like http://yoursapserver:yourport/sap/bc/srt/rfc/sap/yourwebservicename?wsdl, where yoursapserver, yourport and yourwebservicename depend on your system settings and of course on your webservice definition.

Now start Visual Studio and create a new Windows Project. Add a web reference to your Project with the built-in wizard (right-klick in the Project-Explorer, select "Add Web-Reference"). Follow the steps in the wizard, by pasting the address of the WSDL file mentioned above and providing login data. At least, you should give it a name, which will be the name of the Proxy-Class generated by the wizard.

If the wizard finishes successfully, you can use the new class in your .NET-Project. Sample Code (VB.NET):


        Dim cr As New System.Net.NetworkCredential("SAP-Username", "SAP-Password")
        Dim ws As New MyWebProxyClass.ZWHOAMIService
        Dim Result as String
       
        ws.Credentials = cr
        Try
            Result = ws.ZWhoami()
            Me.TextBox1.Text = Result
        Catch ex As Exception
            Me.TextBox1.Text = "Error: " & ex.Message
        End Try

Hope it helps.

Rudi

2 REPLIES 2

rudi_aubermann2
Explorer
0 Kudos

Hi,

assuming that the SAP-side is covered, you should be able to obtain a WSDL-File from your SAP-Application Server. The address of the WSDL-File is somehow like http://yoursapserver:yourport/sap/bc/srt/rfc/sap/yourwebservicename?wsdl, where yoursapserver, yourport and yourwebservicename depend on your system settings and of course on your webservice definition.

Now start Visual Studio and create a new Windows Project. Add a web reference to your Project with the built-in wizard (right-klick in the Project-Explorer, select "Add Web-Reference"). Follow the steps in the wizard, by pasting the address of the WSDL file mentioned above and providing login data. At least, you should give it a name, which will be the name of the Proxy-Class generated by the wizard.

If the wizard finishes successfully, you can use the new class in your .NET-Project. Sample Code (VB.NET):


        Dim cr As New System.Net.NetworkCredential("SAP-Username", "SAP-Password")
        Dim ws As New MyWebProxyClass.ZWHOAMIService
        Dim Result as String
       
        ws.Credentials = cr
        Try
            Result = ws.ZWhoami()
            Me.TextBox1.Text = Result
        Catch ex As Exception
            Me.TextBox1.Text = "Error: " & ex.Message
        End Try

Hope it helps.

Rudi

Former Member
0 Kudos

Now able to call webservice from .Net.Thanks a lot for your valuable information

Thanks,

Anoop