Changes to Web Service not reflected in application that has Web Reference - asp.net

I am required to learn asp.net web services with web forms. I have a web form project that has a web service added as a Web Reference. The problem is, whenever I change anything about the web service (add new methods/services for example), it is not reflected in the application that has the web reference and tells me the new method doesn't exist. How do I fix this?

You have to right-click the web reference and click Update Web Reference to update it manually when the web service contract changes.
Visual Studio will then re-download the wsdl from the service and use it to re-generate the service proxy classes in the client.
Note
Check that you rebuild your web service first, and that those changes are available on the URL used by the web reference in the client project (i.e. if the client app is referencing http://server.mydomain.local/services/CI/myservice/myservice.asmx then just re-building locally won't be enough, you'll need to either deploy the webservice changes or point your client to localhost before you update the web reference.

You probably have to re-import the reference to the webservice. I doubt this definition constantly gets updated like it's a class in your project.

Related

Can't access Newly Added WCF Methods in Web Application

I am developing an Web application using WCF. I have added Web Reference in Web Application. I am adding methods in WCF as per my need then updating Web Reference in Web Application and it is updating successfully but can't access the newly added methods of WCF in Web Application.
Please Help me...
Do your new methods exist in the contract interface, and do they have the OperationContract attribute?
When you update the web reference, is it looking at a test service or your newly-modified service?
Are you running the modified service when you update the web reference, or is it that the old version of the service is running under an ASP.NET process (check your taskbar) and that is what you are updating from?
Have you rebuilt the client after updating the web reference (I know, I know, but easily missed)?
Yes I did it.
I just deleted Web Reference from Web Application and then cleaned the solution of WCF and Web Application. After that Build Solution of WCF. Then added WCF Reference through "Add Service Refeence" then Build Solution of Web Application. In this way solved my problem.

Add reference to service within same project

I'm wondering if it is okay to add a reference to a web service within the same project (web application), i.e. I'm adding a reference in the same project where the service is defined.
The reason for doing so is because
Hosting the service becomes easier (gets automatically hosted when hosting the web app).
Invoking the service is done dynamically, i.e. the service url is fetched (from db) at run time and methods on that particular service are invoked. (this is a web app which is hosted on many domains. each app knows the service url of other apps (urls stored in db). since I have a reference to the service, I can change the url at runtime by updating the Url of the proxy and invoke it.)
Also, I'm not sure if this is the way to go about it. I have seen a lot of people suggest using WCF instead of a web service, but I don't see how I could accomplish the same thing with WCF.
There is already a question regarding this on SO - Add Service Reference to WCF Service within Same Project, but i don't think it is valid for my situation.
If the service is already in your project, you can use it directly without requiring a web service proxy.
After all, Web services are for exposing your application functionality to the outside world and not to other parts of your system.

How to reference web service with my asp.net application

I have my own web service application with more then one .asmx file.
Now i am not getting how can i reference web service with my web application as "Add Web Reference".
I want to connect with both asmx files at once.
Means once i connect web service as add web reference and i can call both .asmx file from my code behind page.
Doesn't work that way. You have to reference each web service or consolidate them.
You could do this:
Invoking Web Service dynamically using HttpWebRequest
When you add a web reference to your application, Visual Studio creates a proxy class that you use to connect to the web service. You will not connect to the web service directly. The proxy class name is set when you add the reference. It suggests a name for you that you can change.
As long as you are using the proxy classes that are generated, you should be able to connect to as many web services as you desire.
I hope that helps.

Consuming a WSE-enabled Web Service in an ASP.NET 2.0 web site

I'm trying to consume a WSE enabled Web Service from an ASP.NET Web Site.
I've installed WSE 3.0, used the config tool to add WSE info to my web.config and then done an Add Web Reference.
I believe that the problem may be that this is a Web SITE, not a Web APPLICATION. As such, the proxy class is generated at runtime, perhaps not adding the WSE magic.
I can access the proxy class from metadata, and it's of type System.Web.Services.Protocols.SoapHttpClientProtocol, which as far as I can tell doesn't have any WSE functionality.
I realize that this is all old technology, but I don't get to decide what the servers run :(
Any help would be greatly appreciated
You are wrong, proxy is generated when you are adding web reference.
Could you tell me how you are adding web reference to the website.
Please refer following article - http://msdn.microsoft.com/en-us/library/5sds7a0b.aspx
After you have located a Web service
for your application to access by
using the Add Web Reference dialog
box, clicking the Add Reference
button will instruct Visual Studio to
download the service description to
the local machine and then generate a
proxy class for the chosen Web
service. The proxy class will
contain methods for calling each
exposed Web service method both
synchronously and asynchronously. This
class is contained in the local .wsdl
file's code-behind file. For more
information, see Web References in
Visual Studio and Add Web Reference
Dialog Box.
Please refer following article - How to Add a Web Reference

.NET and webservices: how?

Im trying to make a webservice in ASP.NET and get the data in a Smart Device Application.
I have the standard HelloWorld webservice and i wanna get the data in my application, but when i try to add a web reference to my project, Visual Studio can't find any webservices running. If i start the WebService in the WebService project and copy/paste the url to the "Add WebReference" in the Application project, Visual Studio finds the Webservice and i can use the InttilSence to find the HelloWorld Method (WebServiceClass.HelloWorld()) in the WebService. But when i then run the Application project the complier gives an error saying that it can't connect to the WebService.
How do i do this? How do i access a webservice in an Application project? Every tutorial or book i have read about the subject doesn't tell anything about how the webservice should i run. In my world the webservice project should be running before i can access it from another project or am i wrong?
Consider reading Rick Strahl's Creating Web Services with .NET and Visual Studio.
From there, you'll get the basics. You can build and deploy your XML SOAP web service.
Then you'll need to have your application use that web service as a 'Web Reference'. Start by "Add Web Reference".
(source: usaepay.com)
First, you should publish the web service to some server (even your own local IIS) rather than using the Visual Studio web server.
Then in your application, point to the correct URL wherever you published it when adding the reference.
While this is a bit low-tech, couldn't you create a web requrest from the Smart Device Application to hit the webservice directly? That would be my suggestion.
An example would be using the "WebRequest" Class.
It sounds like when you try to access the Web Service from your app, the service is not running (possibly because you're only running it in the Cassini server?).
The fact that you were able to generate the Web Reference means that at some point, the service was running and was able to generate the helper classes by examining the service.
I would do as David Stratton suggests and publish it somewhere where it can run while you are developing the Smart Device app (like your local IIS).
You might also take the opportunity to wrap the service call with some error handling - maybe catch the specific exception being thrown (System.Net.WebException?)

Resources