Link to home
Start Free TrialLog in
Avatar of JMO9966
JMO9966

asked on

How to pass a string value to: localhost.IDataCollectionservice()

Hello,

I have an App I wrote that needs to be dynamic in the localhost.IDataCollectionservice() I use for each install.

Private ws As New localhost.IDataCollectionservice()

ws.Url = "http://fs011/datacollection/isapi_dcwebservice.dll/soap/IDataCollection"

I have a function that will retrieve a filepath string, but I need to send this result into the following web service definition for it's URL path.  Here's an example of two paths for two different machines.  I need to insert the machine name and folder into this URL definition setting.

What I need to be dynamic is the macine name(fso11 and morr-2 in the two paths below) as well as the folder names where the web service is installed (DataCollection and Training in my two samples).

ws.Url = "http://fs011/datacollection/isapi_dcwebservice.dll/soap/IDataCollection"
'ws.Url = "http://morr-2/Training/isapi_dcwebservice.dll/soap/IDataCollection"

Thanks,
JMO9966
Avatar of PaulHews
PaulHews
Flag of Canada image

If this is VS 2005, you can set the web service UrlBehaviour property to Dynamic.  This will cause the setting to be saved in your App.Config which can be changed with a text editor, even when your program is deployed.

If VS 2003, you can still save and load from App.Config, but you will need to use appSettings:

Add a new item to your project and select the type "Application Configuration"

Edit the new App.Config so that you have the following information:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
      <add key="machine" value="fs011" />
      <add key="folder" value="datacollection" />
</appSettings>
</configuration>

Now you can use code like the following:


Dim Machine As String = Configuration.ConfigurationSettings.AppSettings.Get("machine")
Dim Folder As String = Configuration.ConfigurationSettings.AppSettings.Get("folder")
ws.Url = String.Format("http://{0}/{1}/isapi_dcwebservice.dll/soap/IDataCollection", Machine, Folder)

Open in new window

Avatar of JMO9966
JMO9966

ASKER

Thanks I run 2005 and am not clear on which of your code snippets to use and which to ignore.

I will check the Dynamic property you referred to.

Thanks,
JMO9966
With Url Behavior = Dynamic, you won't have to use code at all.  The generated file will automatically read the URL from the .config file.
Avatar of JMO9966

ASKER

Thanks, how do I set the URL to Dynamic?

JMO9966
Click on the Web Reference in the Project Explorer window.  Now in the properties window, you'll see the "Url Behavior" property dropdown.  Change it to "Dynamic"  Now you'll be able to change the value in your app.config file.
Avatar of JMO9966

ASKER

Okay, my Web Reference as set to Dynamic.

Now I'm wondering how to changd the value in my App.config file.  I see your code with Get value.

Seems to be that I will first Set and then Get, but I'll have to figure out how to Set the value too.

Dim Machine As String = Configuration.ConfigurationSettings.AppSettings.Set("machine")
Dim Folder As String = Configuration.ConfigurationSettings.AppSettings.Set("folder")
ws.Url = String.Format("http://{0}/{1}/isapi_dcwebservice.dll/soap/IDataCollection", Machine, Folder)
 
Am I on the right track?

Thanks,
JMO9966
Avatar of JMO9966

ASKER

Increasing points too.
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JMO9966

ASKER

Thank You!

I'll give that a try.

JMO9966