Publishing an ASP.net Webservice - asp.net

I have a solution with a number of projects in..
One of these projects is a web application, another is a web service.
The web app references the web service, and uses the methods in there.
In production, the web application will be hosted on one server, while the xml web service will be on another.
My question is, how do i deploy this?
I've "published" the application to the correct server, however what do i do with the xml web service? and how can i configure my web application to point to the other server, rather than try and use localhost....

You generally won't leave your web service proxy classes with their default URL in production code. You can configure the production web service url in your web.config class and then have something like
MyWebService svc = new MyWebService();
svc.Url = WebConfigurationManager.AppSettings["MyWebService"];
Something along those lines should get you what you need.

When you add the proxy to you web application, you can set it to be dynamic url. This will create a config file entry that can be set during your deployment. Click on the Web Reference in the Solution Explorer, change the URL Behavior from Static to Dynamic from properties. An app.config file will be created with a key.

Related

Routing fails when api is created as a web application under another site

I developed a rest api using ASP.net web api. When I deploy this rest api on iis, I need to create it as a web application under an asp.net web site. When I was deploying the rest api as a new web site in iis, then things worked fine. I was using the following Route api/{controller}/{id}.
When I created the rest api as a web application underneath asp.net web site project, I named the web application as api. I can't access the api methods now. Can someone point what I do wrong?
WebApi is based on global.asax and web.config configurations and you can't have 2 of these files inside in the same application. In the scenario you described, it sounds like you need to create a "Virtual Directory" in IIS for the second application instead of making just a "Sub Folder".
The Virtual Directory will allow you to declare a new web.config and global.asax where you set the new routings and configurations method for your second application.
For a full walkthrough on how you can perform this please refer to this site:
http://msdn.microsoft.com/en-us/library/vstudio/bb763173(v=vs.100).aspx

Any modification necessary to web api project web.config when web api project is created as a web application under an asp.net web site?

I have an asp.net web site which runs on port 443 which is https. I also have a asp.net web api which also needs to run on port 443. Because of that, I decided to create a new web application under asp.net web site. I also created a new application pool for that. The problem is that when I try to run web api project, I keep getting configuration file errors. For example it says Default Connection is already added since asp.net web site web.config adds Default Connection already before web api project does. Are there any special steps to take in order to make this work?

How to send data to and from ASP.NET 4.0 website and C# WCF (Web Service)

I am wondering - in my ASP.NET 4.0 website how to connect to the web service I have running?
This is essentially what I would like to accomplish, for testing before I apply it on a larger scale. I want the website to be able to send a value (int) from the website to the getData() method in the web service (auto generated method) and return its result (string) back to the website.
This is my setup for the Website/IIS 7/WCF:
Steps for creating website and service via VS 2010 (.NET 4.0)
Website:
File > New Website
I did not change anything on the default website template
Build > Publish Web Site
Set target location to specific folder
Other settings unchanged
IIS Settings:
Connections - Right Click > Add Web Site
Specified a site name
Specified physical path
Connect As: Set the username/password
Binding Default (http port 80)
Connections - Right Click on Default Web Site > Manage Web Site > Stop
...So as not to end up with two websites on conflicting port
Edit Permissions > Add user "Everyone"
MyNewSite > Manage Website > Start
...Clicked Browse Web Site > Brows *.80 (http)
And the website ran just fine, I was able to access it locally and through vpn with the IP address.
WCFService:
File > New Project > WCF Service Application
...I did not change any of the default settings in the WCF service
I ran WCF service as Admin, and it loaded the little test app where you can type in a value to the getData() method and it returns "You typed {some_number}".
So as far as I know - everything is working with the website and the wcf service. I tried also right clicking on the website in VS, and Add Service Reference and it was able to detect the WCF service.... however, I dont know that I should need to add a reference but simply connect to the WCF like I do to a database via a connection string of sorts.
To elaborate upon my comment, here's a stripped down example. You can find numerous examples of how to do this with a very simple Google search, by the way.
In order for your web site to call any of the methods, it must have a WCF client proxy. This proxy is used to establish the connection to the service and make calls to the methods the service exposes via the [OperationContract] attribute.
Taking your posted example above, if you created a basic no frills don't touch anything WCF Service Application, and you add a reference to it in your website from within Visual Studio, the WCF client proxy will be generated for you, as well as any necessary configuration file settings (in your Web.config file).
Once you've added the reference, you can then do something like the following in your website:
ServiceClient client = new ServiceClient();
string serviceResponse = client.GetData(5);
client.Close();
This would return "You entered: 5" for serviceResponse.
Alternatively, you could use the svcutil.exe to generate a *.cs file and and a config file. You would add the *.cs file to your website project and the <system.serviceModel> section of the config file to your Web.config, and then could use the above code to call the service.
A third way, and this is the way I prefer because of the nature of our application at work and it gives me more control, is to use ChannelFactory<T>, but I would suggest trying the above two approaches to get familiar with the basics first.
Again, see Accessing Services Using a WCF Client, and if that isn't sufficient do a Google search for more examples.
The key point here is that the client requires a proxy to communicate with the WCF service. How you generate that proxy is up to you and the requirements of your project.

Silverlight Web.Config Setting for Web Service Reference URL?

I have a Silverlight control that is hosted within an ASP.NET application. The Silverlight control has a web service reference. The URL of this service is going to vary when we install the application for our customers. I need a way to be able to change this web service reference URL from within the web.config of the ASP.NET application. How can I do this?
You could do something like http://dev/foo/bar.svc where dev is an entry in your hosts file which will resolve to where the service resides.
If you are using Silverlight 4 you can use urls relative to the page the silverlight app is hosted on. So in ServiceReferences.ClientConfig you can change your endpoint addresses to be relative, say from http://localhost/foo/bar.svc to /foo/bar.svc.

Where is the .asmx after I added a localhost webservice?

When I added service -> web service. The VS2008 added a App_WebReferences folder without a .asmx file. I see a .discomap file.
When I use the cascading drop down ajax control, it is looking for .asmx in the service path. Am I doing it wrong? I remember the early edition of Visual Studio added a .asmx file when you added a outside webservice reference.
EDIT:
I don't think I'm clear on my question. I have a ASP.net Webservice application that is setup on localhost/service. I want to reference to that service in my asp.net website. I first added the project to the service in the soultion add existing project then on my website i added the web reference via localhost/service. It now have a folder App_WebReferences and the service folder along with service.discomap, service.disco and service.wsdl
when i try to use the cascading drop down extension. the service path is looking for .asmx file so how do i setup the service path for the ajax extension?
If the dropdown needs to call the web service, just give it the URL of the web service (ex: http://localhost/mywebservice/service1.asmx). I believe you'll also need to give it the name of the web method to call.
You won't need to add a web reference to your project unless you plan to call the web service manually.
You added a reference to an external service. You'll want to create a new web service by right clicking on your project, then Add New Item and selecting Web Service.
Also note that if you make a folder, say, WebServices, and add the asmx there, it'll place the .cs file in App_Code. If you have a web application project, I'm not sure where it would put it since there is no App_Code.

Resources