How to call web service dynamically?
-
I have a vb.net desktop control hosted in a webform. I need to vall a web service method from this control. Since I can't use a config file for a control hosted in a browser, I am not sure how to add a web reference and call the web method. If I select the 'web reference' property as 'static', then I will end hard coding the web service url. If I select 'dynamic', it is looking for the config file. How can I call a web service method in this scenario? I will not know the web service url at the time of compilation. Only during deployment I will get this URL. - ToJo
-
I have a vb.net desktop control hosted in a webform. I need to vall a web service method from this control. Since I can't use a config file for a control hosted in a browser, I am not sure how to add a web reference and call the web method. If I select the 'web reference' property as 'static', then I will end hard coding the web service url. If I select 'dynamic', it is looking for the config file. How can I call a web service method in this scenario? I will not know the web service url at the time of compilation. Only during deployment I will get this URL. - ToJo
Hi there, You can use WSE. WSE supports both a one-way messaging model with the SoapSender and SoapReceiver classes and a request/response pair model using the SoapClient and SoapService classes, you can take a look at Sending and Receiving SOAP Messages [^]for more information. So in this case, you may consider using the SoapClient to send the message and receive the response, the sample code looks something like Option Explicit On Option Strict On Imports System.Net.Dns Imports System.Net Imports System.IO Imports System.Threading Imports System.Xml Imports System.Web.Services Imports System.Text Imports System.Text.RegularExpressions Imports System.Globalization Imports Microsoft.Web.Services2 Imports Microsoft.Web.Services2.Messaging Imports Microsoft.Web.Services2.Addressing Imports System.Security Public Class LoadTesterForm Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As System.Windows.Forms.Label Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox Friend WithEvents Label4 As System.Windows.Forms.Label Friend WithEvents Label5 As System.Windows.Forms.Label Friend WithEvents TestReport As System.Windows.Forms.TextBox Friend WithEvents Label6 As System.Windows.Forms.Label Friend WithEvents WebServiceURLTextBox As System.Windows.Forms.TextBox Friend WithEvents ConnectBtn As System.Windows.Forms.Button Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox Friend WithEvents MethodTextBox As
-
I have a vb.net desktop control hosted in a webform. I need to vall a web service method from this control. Since I can't use a config file for a control hosted in a browser, I am not sure how to add a web reference and call the web method. If I select the 'web reference' property as 'static', then I will end hard coding the web service url. If I select 'dynamic', it is looking for the config file. How can I call a web service method in this scenario? I will not know the web service url at the time of compilation. Only during deployment I will get this URL. - ToJo
Just look at the ConnectBtn_Click sub & MyHTTPClass. Rest is not of your use. Thanks Sumit Domyan
-
I have a vb.net desktop control hosted in a webform. I need to vall a web service method from this control. Since I can't use a config file for a control hosted in a browser, I am not sure how to add a web reference and call the web method. If I select the 'web reference' property as 'static', then I will end hard coding the web service url. If I select 'dynamic', it is looking for the config file. How can I call a web service method in this scenario? I will not know the web service url at the time of compilation. Only during deployment I will get this URL. - ToJo
Hi there, Instead of adding a web reference to your window control project, you can manually add the proxy class to the control project. You can find the proxy class generated by VS in the Web References folder or you can create the proxy on your own using the tool Wsdl.exe. The next step you need to do is to find out the way to pass the url of the web service from the control to the proxy via the
URL
property of the proxy. As you already know that to host a window control on a web page, you would normally use theobject
tag, and the nested elementParam
of theobject
tag can be used here to pass a parameter to the control. So you simply declare a Param element:<OBJECT id="MyWinControl1" height="300" width="300" classid="..." VIEWASTEXT>
< PARAM NAME="WebServiceUrl" VALUE="http://intello/WebService1/Service1.asmx">
</OBJECT>And you also need to define a public property called
WebServiceUrl
in the window control to store the value of the parameter.