Calling ASP.net Web Service from C# Application - c#

I have a question. How can i invoke a web service and get the result from a C# desktop application. I am making a desktop app and I want it to be able to connect to my online ASP.net web services. How is this possible?

In Solution Explorer, right-click your project node and select Add Service Reference.
Enter the URL where your service WSDL is located. This is usually the URL of the service itself.
This generates a strongly-typed proxy class in a new Services References folder in your project.
Write code in your desktop app to instantiate the proxy class and invoke methods on it. The rest works like magic. :)
AB Kolan was also correct, but Add Web Reference uses the old-style web services framework whereas Add Service References uses the new WCF stack. Important note: It is not required that the service itself use WCF for you to use WCF on the client side. WCF on the client is typically the best choice for any service, provided you can take a dependency on .NET 3.0 and above.

Add a Web Reference to the webservice in your Desktop App project reference. Doing so would generate a Proxy for the Webservice called Reference.cs
You can access your webservice using the proxy.

This is possible the same way that you access web services from any other type of application, be it an ASP.NET page, a class library or windows service.
For an explanatory tutorial on the subject, see Accessing a Web Service from a Desktop Application.

Will get help how to create a webservice and consume that service:
http://www.c-sharpcorner.com/UploadFile/0c1bb2/consuming-web-service-in-Asp-Net-web-application/
Thanks

Related

Create an ASP.NET Web API using a Console application

I have seen many articles in Internet to create a RESTful Web API by selecting the WebAPI project as project type. Is there any possibility that we can create the same using console application. If possible, how can it be hosted? How does an executable file gives us the URL to consume from the client application?
Yes, there is a possibility. but we need to flow some steps to achieve this.
we should use OwinSelfHost package for self hosting.
we should create as class file that inherits from ApiController.
install cors package for webapi application that is used for client to consume the application.
Hosting:
domain name or IP should be given where the service is hosted.
Reference Example

Variable Service Reference Endpoint in C# and Visual Studio

Excuse my ignorance if this is something basic, I am somewhat new to the whole C# console application, using a Web Service Reference (WCF).
I am creating an application that will be places as an executable on many different machines and acts as a client to a web service. however, the web service is also installed in the client's local intranet, so the endpoint will change for each location.
I see the web reference endpoint is in the app.config file when adding within Visual Studio, but is there a simple way to change the endpoint at runtime, verify the endpoint is correct and exists, and be able to use the methods?
Also, if this is possible would I still need to add the SVC as a service reference in my Solution or would I call it dynamically?
I am using C# and .Net 4
Thanks
You can put the address as an AppSetting and set it after creating your proxy class:
Proxy.Endpoint.Address = new EndpointAddress("myconfigvaluehere");
First - there's excellent book about WCF services by Juval Lowy: Programming WCF Services: Mastering WCF and the Azure AppFabric Service Bus. He explains along the book about WCF wrapper class that connect to WCF service dynamically using Endpoint, Binding and all that jazz. But you need to understand WCF background to continue working with it <- and you can do it from the book :)

Reference C# Windows Service into an ASP.NET web application, is it possible?

I have developed a C# Windows Service application with certain methods that I would like to call from an ASP.NET web application (it is important that there are these methods returning the result). My initial guess was that I could import the dll of the Windows Service into the web application, but I can find only the executable of the windows service, there's no dll at all.
Is it possible to compile the Windows Service into a dll? And if not, is there some other way I can reference my Web Service into the Web application?
Extract the common functionality into a class library project and reference it from both projects.
Is your windows service hosting a web service or does it just contain code that needs to be accessible in you windows service and web site?
If the former, then you can connect to it via the normal mechanims for connecting to a web service (e.g. adding a service reference in Visual Studio). If the later, then create a class library that both your windows service project and web project can reference (via Add Reference in Visual Studio).
You have two options. If you just need the code to be invoked, then you can call the windows service functionality via a custom action on the service, invoked from your code.
However, I gather that what you require is more complex, requiring a response as well. In this case, as per sga101, encapsulate the appropriate functionality into a separate class, and use this in both places. This means that the code projects should both be included in the same solution ( it is not strictly necessary, but it makes it easiest to keep the code matching ).

.net web service hosted within my application

I'm migrating an old Delphi application that I wrote into C#. The application is a datalogger that exposes logged data requests via a SOAP web service interface.
The web service is contained with the delphi graphical windows application, i.e. no need to run a web server like IIS, etc I just run the application and it's up and running under the hood.
I'm looking to do the same in my c# Windows form application, I can find loads of resources on writing web services that are ultimately hosted within IIS but am struggling to find a solution for a self contained web service within my application.
Does anyone have any suggestions or can point me towards any resources on this?
The web service does not neceserily have to be SOAP, REST is fine (in fact probably prefered).
Look into WCF Services.
Hosting and Consuming WCF Services
Hosting WCF services in a Windows Forms Application
The System.Web.Hosting namespace allows you to host ASP.Net pages without using IIS within your applications. I have never used it to host web services but I found a tutorial that seems to provide a guide on doing this-
http://msdn.microsoft.com/en-us/magazine/cc163879.aspx
If you're wanting to host a service inside your application, it's possible with the System.ServiceModel.ServiceHost class. You need to learn WCF first, but that at least answers your question to get you started. If you have any further questions, leave me a comment or two and I'll update my answer to accommodate your inquiries.

Wcf proxy generation on windows mobile application

For my mobile app, I used the Add Web References to generate the client proxy to interact with my WCF service.
Then I read somewhere there is an equivalent of SvcUtil for compact framework: NetCFSvcUtil.
Should I be using the NetCFSvcUtil instead of going throught the Add Web References? Or the Add Web References uses NetCFSvcUtil in the background?
Any pros/cons of one or the other?
Add web reference should be old proxy based on ASMX web services whereas NetCFSvcUtil is tool to generate WCF based proxy. For basic web services there is generally no difference - both will work but if you want to use some advanced WCF features available on CF you will have to use NetCFSvcUtil.

Categories

Resources