Avatar of MikeCombe
MikeCombe
Flag for United States of America asked on

How to use web.config, asmx and default.aspx

I am having a problem getting my DEFAULT.ASPX file to get the connection in the WEB.CONFIG file, which is calling on a webservice asmx located on a website server. Below are my settings in the web.config file and the default.aspx file.

Notes:
1. I hand coded these files, so there are no other files in play.
2. When I use Visual Studio 2005, there are lots of other files. However, when I copy the files to my website server, I encounter other issues. I cannot use the 'publish' feature in VS2005. I am just trying to run a test to see how the ASMX file works. In this case, the ASMX file is returning a dataset, which the default.aspx file will display to the user.

Questions:
1. What am I doing wrong?
2. Does the asmx file, or something else need to be compiled before I upload it to my server?
3. Where is the location of the web.config file? Can it be in the sub-folder where default.aspx is or does it need to be in the website root folder?

[web.config]
<configuration>
<appSettings>
<add key="ABC.Test" value="http://www.mywebsitee.com//WebServices/Test.asmx"/>
</appSettings>

[default.aspx]
Sub gv_Clients_Load()
    Dim ws As New ABC.Test      <---- Error here, see msg below
    gv_Clients.DataSource = ws.GetClients
    gv_Clients.DataBind()
End Sub

[default.aspx      Error Message]
Compiler Error Message: BC30002: Type 'ABC.Test' is not defined.


WCFASP.NET

Avatar of undefined
Last Comment
strickdd

8/22/2022 - Mon
strickdd

To call a web service, you need a proxy class of some sort. To easily do this, you should add a web reference to that web service URL you posted. Then you can instantiate an object of that type as you have in your code.

On another not, to reference something in the web.config appSettings section, it is like this:

System.Configuration.ConfigurationManager.AppSettings["ABC.Test"]
MikeCombe

ASKER
>>>>>>>>>>>>>>>>>>>>>>>>>>
To easily do this, you should add a web reference to that web service URL you posted.
<<<<<<<<<<<<<<<<<<<<<<<<<<

How do I do this ?
MikeCombe

ASKER
>>>>>>>>>>>>>>>>>>>>>>>>>>
On another not, to reference something in the web.config appSettings section, it is like this:
System.Configuration.ConfigurationManager.AppSettings["ABC.Test"]
<<<<<<<<<<<<<<<<<<<<<<<<<<

changing......

[default.aspx]
Sub gv_Clients_Load()
    dim ws as New System.Configuration.ConfigurationManager.AppSettings("ABC.Test")
    gv_Clients.DataSource = ws.GetClients
    gv_Clients.DataBind()
End Sub

error;;;;;;

Compiler Error Message: BC30002: Type 'System.Configuration.ConfigurationManager.AppSettings' is not defined.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
strickdd

If you right click on your project or website and Add Web Reference, follow the wizard, and VS will create the proxy class. Make sure to call the web reference ABC.Test and your code will then look like:

dim ws as New ABC.Text()

The "System.Configuration.ConfigurationManager.AppSettings("ABC.Test")" line of code was merely to show you how to reference a value from the appSettings, you cannot instantiate and object from a string key.
MikeCombe

ASKER
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
If you right click on your project or website and Add Web Reference, follow the wizard, and VS will create the proxy class. Make sure to call the web reference ABC.Test and your code will then look like:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

I understand what you are saying......but I don't want to use VS to build my project.
I am trying to find the code that I need to run my asmx file.
I should be able to hand-code without VS.
ASKER CERTIFIED SOLUTION
strickdd

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.