Calling Web Service from codebehind?
hi
in our project UI project is in Machine1 and web service is in another system.
how can i call the webservice with help of that system's IP address in my asp.net? [without using the webreference or any tool] Is there any way to achieve this with system.net namespace?
Can anybody help me in this context?
Re: Calling Web Service from codebehind?
Run the wsdl.exe tool:
Code:
wsdl.exe /language:VB /out:C:\abc.vb http://XXX.XXX.XXX.XXX/servicename/service.asmx
This will create a proxy class for you. Everytime you want to use a method from there, instantiate it, and use away!
Re: Calling Web Service from codebehind?
Quote:
Originally Posted by mendhak
Run the wsdl.exe tool:
Code:
wsdl.exe /language:VB /out:C:\abc.vb http://XXX.XXX.XXX.XXX/servicename/service.asmx
This will create a proxy class for you. Everytime you want to use a method from there, instantiate it, and use away!
ok im getting ur point about WSDL. but, if i deployed the UI in one system and WebService in another system(with some modification) how can i access the latest one. i have to recompile my code each time.
Re: Calling Web Service from codebehind?
Store the URL for the webserver name in a config file. In your proxy class, have the constructor only allow an argument to be passed to it, which would be the name of the webserver picked up from the config file.
Re: Calling Web Service from codebehind?
Just to clarify, here's an example:
First, I modified the constructor of the proxy class:
VB Code:
Public Sub New(ByVal strWebServiceServer As String)
MyBase.New()
Me.Url = strWebServiceServer & "EmployeeManager.asmx"
End Sub
Then, from my pages, I call it like this:
VB Code:
Dim em As New EmployeeManager(Configuration.ConfigurationSettings.AppSettings("WebServiceServerName"))
Re: Calling Web Service from codebehind?
Quote:
Originally Posted by mendhak
Just to clarify, here's an example:
First, I modified the constructor of the proxy class:
VB Code:
Public Sub New(ByVal strWebServiceServer As String)
MyBase.New()
Me.Url = strWebServiceServer & "EmployeeManager.asmx"
End Sub
Then, from my pages, I call it like this:
VB Code:
Dim em As New EmployeeManager(Configuration.ConfigurationSettings.AppSettings("WebServiceServerName"))
i dont know how to create the proxy from my coding and access the webmethods?
Re: Calling Web Service from codebehind?
Eh? Didn't understand you...
Re: Calling Web Service from codebehind?
Quote:
Originally Posted by mendhak
Eh? Didn't understand you...
hi,
i saw one article about using system.net namespace and its classes to call webservice. but im not getting that webarticle now. how can we use system.net namespace to call webservice and methods from codebehind?
Re: Calling Web Service from codebehind?
What I just showed you does just that. All your calls are from codebehind. If this isn't what you're asking for, show me the article you had seen...