I'm new to the WCF, and I'm looking for some advice. In my web app I consumed a web service (R+Click on project - "Add Web Reference") and started coding. My web app is really big, so it was taking forever to compile each time I wanted to debug, so I built a stripped down WinForm using the same code.
In VS2008 there is no "Add Web Reference" option when using the 3.5 framework, so I just chose "Add Service Reference" and used the same url. The objects/methods that I now have access to are completely different when compared to the objects/methods in the web app after consuming this as a web service.
Is that normal? Is this somehow related to the WCF?
Thanks
You can still add web references.
Do
Add Service Refernce
Hit the "Advanaced" button on the bottom left
Hit "Add Web Reference" on the bottom left.
Yes this is related to WCF. When your project target is >= .NET 3.0 the Add Service Referemce option will be available which will use svcutil.exe to generate client classes, otherwise you will have the Add Web Reference option which uses wsdl.exe. WCF clients use different classes to call a web service and that's why you get different classes generated.
Related
At the minute I am building an ASP.NET MVC application to learn the technology, and I want to incorporate web services as I have never used them before and I want to have experience with them.
I was wondering would it be possible to create a web service and run it on the Visual studio local host along with my MVC application an then consume it with the MVC application.
I am hoping that the web service will basically pull data from the the same db as the app and then allow the mvc app to consume the service. Would this be possible?
Sorry if this is a pointless question but it is for a college project. Any help greatly appreciated
Thanks
Yes, it is very possible with Visual Studio - in fact, it is easy. Best to follow some tutorials - one such tutorial is http://www.asp.net/mvc/tutorials/mvc-music-store.
For more specifics about the service from within VS, this link may be more helpful - msdn.microsoft.com/en-us/library/cc668184(v=vs.100).aspx
If you are talking a WCF service, this is very easy to do. You'll want to add the service to the same solution as your MVC project, right click on References in the MVC project, then click add service reference. On the dialog that comes up, click discover to the right and it will find the service in the solution allowing you to add it locally.
Once you have a service reference, you can right click and configure to see the path. Should be set to localhost in this case. Doing this will allow you to set breakpoints and debug the service through your MVC application.
I am using Visual Studio 2010 and I am trying to create a solution containing an N tier architecture.
I have a project each for every tier
Common
DAL
Business //
Service // WCF
ServiceHost
Web
the projects are listed above are also called in the same order as well; so Web talks to Service tier, service tier talks to Business and business then talks to factory and factory project is responsible for talking to DB.
the issue I am having is to setup my projects in a way that before Web project is launched by pressing F5 - ServiceHost (which is just a self host console for WCF) should be started first so when Web calls for a service; it is up and running already.
Note: in PRD; Web and WCF will be hosted on different boxes altogether so this wont be an issue but for developing on Local machine - I need the above.
Interim Solution - I have excluded ServiceHost Project from the solution so it doesnt get launched with Web and I am running the ServiceHost executable externally from command line to get the Service up and running and then I am launching the Web project as normal using F5.
Can someone please tell me what do I have to do to achieve the above?
As Rajesh suggested, you set multiple projects to start in a multi-project solution. To do this, select DEBUG -> Set Startup Projects (or right-click on the solution and select Set Startup Projects... from the context menu.
This will give you a window that lists all your projects in the solution. Check the "Multiple startup projects" radio button, and set the Action column to "Start" or "Start without debugging" for each project you want to run. You can use the up and down arrows to specify the order.
If your web application requires the service to be available when it starts (i.e., the web site calls the service during it's initialization/startup), you may be better off doing as you are now (running the WCF service from the command line), otherwise this should get you where you want to be.
Attached is a screenshot (VS 2012) with a solution similar to the one you outlined above:
We have an ASP.NET 2.0 site. A 3rd party has created a web service that we are supposed to connect to, and I was naively expecting a 2.0 style web service to be created. When I was given the url, I was expecting to see a .asmx suffix...but instead was given a url with .svc suffix.
Going to that page tells me to to create a WCF client by running svcutil...but, again, we aren't running .NET 3.0+ yet.
Since it's a web service, I'm thinking the basic functionality should be essentially the same, but freely admit I know essentially nothing about WCF (yet.)
Can I expect this to work eventually, or is there some kind of potentially blocking issue (WCF web services being inherently different in some profound way)? Is there a simple path for creating a basic client (like svcutil would if we were in the 3.0+ world)?
If it's using BasicHttpBinding (SOAP 1.1) it's probably interoperable.
In the "Add Service Reference" dialog in VS2010, click on "Advanced", then click on the "Add Web Reference" button.
I have several asp.net website projects for various sites.
Currently I want to add REST API's to these projects so I can start developing mobile apps (using HTML5/JavaScript/CSS3 and PhoneGap) that make use of these webservices.
Since WCF is far more powerful than regular asp.net webservices (among others with control over the service and authentication/authorization), I'd love to add these to my existing website project.
I did a Google search but cant find anywhere a step-by-step tutorial how this can be done. And also if there's any functionality I'd possibly loose when adding WCF functionality
I was also thinking of creating a new project specifically for WCF, but think I'd rather add it to an existing website project.
Can anyone help me with this?
Depending on exactly what your needs are and how your current web site is configured, there are two approaches.
If you are using a Web Site Project, then you should create your WCF service in a different application:
1) Create a new ASP.Net Web Application Project.
2) Add a new item to the project and select the type of WCF Service or WCF Data Service.
When you deploy this project, you will deploy it to your web server, but not as part of your web site since configuring the web.config will be a large manual effort.
If you are using a Web Application Project, then you could add the WCF Service directly to your existing project. However, I only recommend this approach if you are Silverlight applets within the web site that rely on the user's authenticated credentials.
WCF can be configured with a lot of bindings and it can be configured to return xml or json(.net 4.0). Try to create a wcf service configured to use basichttpbinding or wsHttpBinding and to format the response as json and use jquery to interact with the wcf service. This article might help you http://www.codeproject.com/KB/aspnet/Cross_Domain_Call.aspx
I've written an ASP.NET website along with a companion WinForms desktop application, which is used to maintain the site.
The desktop application needs to create a user. However, this is awkward because I would need to ensure all the membership settings are exactly the same as they are in my website's web.config file.
It would be easier if my desktop application could "call into" the website somehow and tell it to create a user. It seems like a web service would be a good option for this. However, Visual Studio doesn't have an option to add an ASMX file. And if I create a separate, web service application, then that application would have the same problem my desktop application has.
Is there a way to add a single web service to an existing ASP.NET application? Any links? Thanks.
Visual Studio doesn't have an option to add an ASMX file
In the Web application project, or the WinForms project? I assume you mean that you cannot add a Web Reference from within your WinForms project; adding an .asmx file to the WinForms project is not necessary. The Web application project should have the .asmx file, which is called by the WinForms project using a web reference.
In the WinForms project you can consume a web service by right-clicking References in the Solution Explorer, then choosing Add Service Reference... (in Visual Studio 2008; other versions may say Add Web Reference...). Then just enter the web address (which may be local in your case, e.g. localhost/foo.asmx) of the web service (.asmx).
See the section "To call an XML Web service synchronously" in this MSDN article: Calling XML Web Services from Windows Forms.
As an alternative, this MS KB article shows how to use the WSDL tool to generate a class that can consume a *.asmx URL. (The article uses VB, but you can switch the parameter to CS to generate C#.)
Update
To add an .asmx file to your Web project, right-click the project in Visual Studio, select Add -> New Item... -> Web Service. If there is not a "Web Service" item any where in the template browser dialog that comes up, then you are missing the template or you're looking in the wrong place.