.NET and webservices: how? - asp.net

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?)

Related

Starting point of Azure WebApp

I opened a new .Net Framework WebApp and I am using it with Azure.
At the very first point, when I run the App from Visual Studio, it opens the browser and shows the default page:
I was looking for a "main" class or method but could not find one. I am wondering where does it start from? how this thing works?
If added a new method for which I want to run together with the WebApp, where should I call it from ?
I am wondering where does it start from? how this thing works?
This is about how does asp.net webapp run.When the application starts up, it runs Global.asax’s Application_Start() method. In this method, you can add Route objects to the static RouteTable.Routes collection. These will be inspected later when each request is received. Each Route object defines a URL pattern to be matched and the controller to be used in this case.
For more detail about how the Asp.net webapp run, you could refer to this article and this one.
If added a new method for which I want to run together with the WebApp, where should I call it from ?
When you publish to azure and add a new method in a controller, you could call it like yourappname.azurewebsites.net/Controllername/methodname. It mainly depend on your Rounte, you could refer to this article.
Azure App Service Web Apps is a service for hosting web applications, REST APIs, and mobile back ends. You can develop in your favorite language, be it .NET, .NET Core, Java, Ruby, Node.js, PHP, or Python. Applications run and scale with ease on Windows-based environments.
With App Service, you pay for the Azure compute resources you use. The compute resources you use is determined by the App Service plan that you run your Web Apps on.

Calling WCF service from jsp page

I have created a WCF Service and published it to a Windows Server running IIS. In an asp.net web application, I can add a Service Reference to the WCF Service which exposes its methods which I can call. This all works fine.
I need someone who is running a jsp site to be able to call a method in my WCF Service. How can they do that? (I know absolutely nothing about jsp). Presumably they cannot reference my WCF Service within their application in the same way you can within a .net application.
The web services are totally platform independent. Therefore, someone writing in Java should have no problem calling a web service server, regardless if it was written using WCF or another platform. For example, here, here and here you could find some tutorials on how to build web service clients using java. This java code could be called from JSP pages.
If you want to quickly test your web service from the client side, you could use SoapUI. It's a web service client tool developed in java. I am sure you will find it useful.
Hope I helped!

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.

How to call WCF at a scheduled timings?

I have to export data from a database in the form of flat files. I already have an asp.net website which saves data into the db. I am thinking of creating a WCF webservice project as part of the website solution. This WCF webservice will have methods to export flatfiles. I am also planning to create a console app to call this webservice at scheduled times.
I have the following questions:
Once the website is hosted on IIS along with WCF, can the console app call the WCF or WCF has to be hosted separately?
How to debug the process?
is there any better way of doing it?
Once the website is hosted on IIS along with WCF, can the console app
call the WCF or WCF has to be hosted separately?
The console app can call the WCF web service. It does not have to be hosted separately.
How to debug the process?
Ideally, on your own PC. Easy way to do is to launch the WCF Webservice within one instance of Visual Studio and the Console App on another instance of VS. You can put break points on each of the projects and follow the logic
is there any better way of doing it?
There are many ways to do one thing but yours in this case looks good to me.
Your plan sounds fine to me.
If I were doing this I might create a WCF Service with One Way Operations so that the client app is not waiting for a response until the job is complete.
I might use Powershell and a scheduled task to hit the WCF service, or even use the free Pingdom service to hit the service endpoint at intervals.
To debug locally- if the WCF is it's own project make sure it's set as the startup project in VS, then apply break points, run debug and request the endpoint through the browser or Fiddler.

Changes to Web Service not reflected in application that has Web Reference

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.

Resources