Last post Aug 14, 2017 05:03 PM by TechView
Aug 14, 2017 02:53 PM|TechView|LINK
I am having problem to consume a web service in an ASP.NET (Web From) application. The web service is written in C# and it should be an easy one to call in the ASP.NET project. The error is when I add the web reference in the project, it creates a folder
Web References with localhost and in it, URL of the web service is given like this -
http://localhost:1234/MyCustomers.asmx. So I created a web form and in the code behind, put the namespace as follows:
Finally created an object of the service using the following code:
GetCustomersApp.localhost.MyCustomers services = new GetCustomersApp.localhost.MyCustomers();
I can get the namespace wherever I write the project name in the code-behind. That means it gets the namespace localhost perfectly. But when I run the project and in the browser, I am getting this:
The type or namespace name 'localhost' does not exist in the namespace 'GetCustomersApp' (are you missing an assembly reference?)
I guess, this isn't an issue of .NET framework and using .NET version 4.5.1. By the way, I can run the service and it creates data in Xml format or converts into Xml in the browser. Any way to get rid of this?
Note: The web service is in another project and the reference is given to include in the current project. Below is a sample image how I've added the web reference and got the namespace 'localhost':
Aug 14, 2017 03:48 PM|A2H|LINK
You dont need to add localhost in your namespace and method declarations while consuming webservice. Please find the sample application code I tried
Added the below namespace to page
and then access the method like below
//Creating client for webservice
GetCustomersApp.MyCustomers client = new MyCustomers();
//Calling the method in webservice
string t = client.HelloWorld();
Aug 14, 2017 05:03 PM|TechView|LINK
Hello A2H! Thanks for the reply. I tried the way that you showed but didn't work. Without the localhost namespace, I am unable to access the 'MyCustomers' web service. Any
other way? Thanks again.
Update - 1: Done - It worked. Just took a new project and working as supposed to be.