Adding a Single Web Service to an Existing ASP.NET Application - asp.net

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.

Related

Do I need to select web Site or Web project?

I am completely new to .net framework. I have to build a website that contain real time updating graphs.
data takes directly through MS SQL database via web service. (Website contain graphs only which should update time time)
I noticed that VS 2015 has 2 options. web site and web Application.
Which one should I use for my project. Please guild me to select best option.
IMHO Web Application all the way. And use the publish wizard to deploy.
Web sites do not have a project file: everything in the project folder (and subfolders) is part of the project. This seems nice and easy until you want to be able to include/exclude things. It also assumes all the compilation is done on the web server (on the first load of each page). In practice in the medium to long term leads to work-arounds that would be unnecessary in a web application.
web Application. Click on start Page -> New Project -> ASP.NET Web Application
Click on File -> New Project -> ASP.NET Web Application

Web API project template in VS

Why can't we create WebAPI project directly just like "WCF Service Application" template in VS.I want to create separate solution not using MVC or ASP.Net WebForms template. In our project we intend to have service layer on different physical machine hosted by IIS to be consumed by different web applications.
The ASP.NET team is in the process of making their offering more cohesive, an effort they call "One ASP.NET." Under One ASP.NET, MVC, Web Forms, Web API, SignalR, and Entity Framework are all first class citizens. They want to make it easy to create web applications that utilize these technologies without having to give up the others; that is, you can make an MVC project but still use Web Forms; or a Web Forms project can easily add a Web API Project.
Anyway, back to your question: you can't create a Web API project directly (i.e. it's not in the main project template list) anymore because it has been rolled into the the single ASP.NET project type.
They explain,
Starting with Visual Studio 2013, the guessing game about which
project type to choose is over. There is now only one web project type
in Visual Studio.
As you can see from the list of templates, we can choose to start with
a standard Web Forms, MVC, or Web API project type. The other project
types from the old MVC template dialog are still here. The interesting
part is the checkboxes underneath the list of templates. Here, we can
choose to add Web Forms references and folders to an MVC project, or
MVC references and folders to a Web Forms project. This is the gateway
to using more of these features in concert with each other in your
project.
Read the full MSDN blog article about One ASP.NET and the new project types here
You can, however, still create a project (or solution) that contains just the Web API references. Just use the ASP.NET project dialog to choose the Web API project type, and make sure all the other check boxes are unchecked. You'll be able to make your project just for Web API, and then go host it on a dedicated box for your services layer. It's all still there, the UI just looks a little different.

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.

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

Why was the Profile provider not built into Web Apps?

If you create an ASP.NET web file project you have direct access to the Profile information in the web.config file. If you convert that to a Web App and have been using ProfileCommon etc. then you have to jump through a whole bunch of hoops to get your web app to work.
Why wasn't the Profile provider built into the ASP.NET web app projects like it was with the web file projects?
Actually, Microsoft does have a solution for this known issue.
It's the "Web Profiler Builder". I used it for my Web App and it works great.
http://code.msdn.microsoft.com/WebProfileBuilder/Release/ProjectReleases.aspx?ReleaseId=980
The profile provider uses the ASP.NET Build Provider system, which doesn't work with Web Application Projects.
Adding a customized BuildProvider
class to the Web.config file works in
an ASP.NET Web site but does not work
in an ASP.NET Web application project.
In a Web application project, the code
that is generated by the BuildProvider
class cannot be included in the
application.
source: MSDN Build Provider documentation

Resources