Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to call web service dynamically?

How to call web service dynamically?

Scheduled Pinned Locked Moved ASP.NET
questioncsharpsysadmintutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    T Manjaly
    wrote on last edited by
    #1

    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

    S M 3 Replies Last reply
    0
    • T T Manjaly

      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

      S Offline
      S Offline
      Sumit Domyan
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • T T Manjaly

        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

        S Offline
        S Offline
        Sumit Domyan
        wrote on last edited by
        #3

        Just look at the ConnectBtn_Click sub & MyHTTPClass. Rest is not of your use. Thanks Sumit Domyan

        1 Reply Last reply
        0
        • T T Manjaly

          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

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          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 the object tag, and the nested element Param of the object 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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups