How to publish a Web Service from Visual Studio into IIS? - web-services

I have written a WCF web service in C#. I had originally self-hosted it and then decided to host it on IIS running locally on my PC. While the service is working, there are several aspects of the deployment process that I don't understand:
Firstly, the URL of this service when hosted in IIS does not correspond to what I specified in my web.config. I had specified "http://localhost:8000/MyServices/OrderService" there and this was used when I self-hosted. Now that I've deployed to IIS, the URL has become "http://localhost/MyServices/OrderService". Why is the URL not picked up from my config file?
Secondly, to host the Web Service, I created a new web site within IIS (in addition to the existing 'Default Web Site'). I set the physical path to c:\inetpub\wwwroot (no idea if this is correct) and left the other parameters as default. I then copied my /bin folder, my .svc file and my web.config to this folder. Is this the equivalent of a 'Virtual Directory'?
Finally, the service didn't work until (within IIS) I selected 'Convert to application'. Why is it necessary to select 'Convert to application'?
Can anyone explain what the correct procedure is to publish a simple web service from Visual Studio into IIS, or point me at some good documentation so I can understand the process?
****EDIT TO ORIGINAL*****
Having spent more time looking into this, I have found the following:
When I create a web site in IIS, I give it a physical directory of c:\inetpub\wwwroot....etc
If I then "publish" from within Visual studio, all it's doing is copying all the required filed (like the /bin directory, web.config and .svc file) into the physical directory of the website i.e. - c:\inetpub\wwwroot...
You can perform the copy manually to the same affect.
Lastly, with regard to the URL of my service not corresponding to the baseAddress section of my web.config file, this has been answered on stackoverflow previously.
The answer is that the baseAddress is completely ignored when hosting on IIS.

If using Visual Studio 2010 you can right-click on the project for the service, and select properties. Then select the Web tab. Under the Servers section you can configure the URL. There is also a button to create the virtual directory.

Related

404 On existing .svc file

I have an IIS site on a Windows 2012 R2 server. The site has an Application inside it:
The URL for this site is setup on our Active Directive servers as it is only accessible internally from our company. The URL follows the following structure:
http://NAMEoftheSERVICE.myCompanyServices.myCompany.local
The service for this site is placed in an internal folder:
http://NAMEoftheSERVICE.myCompanyServices.myCompany.local/InternalFolder/Service.svc
I have placed a number of test files both at the root level and in the internal folder:
http://NAMEoftheSERVICE.myCompanyServices.myCompany.local/HelloWorld.html
http://NAMEoftheSERVICE.myCompanyServices.myCompany.local/InternalFolder/HelloWorld.html
I can browse these files without any problems. However, I cannot browse the service at http://NAMEoftheSERVICE.myCompanyServices.myCompany.local/InternalFolder/Service.svc
The browser returns
However the file is there, and I have made sure there are no typos in the URL I put in the browser.
I have looked at similar questions but there seems not to be anything like the problem I am experiencing. The only question that looked promising was:
WCF service file not visible
But the answer for that post does not apply to my issue as I already have the configuration mentioned in that post setup as it is suggested.
I have checked the IIS-level config files for any exclusion regarding .svc files or anything similar, but could not find anyhting.
Have you got any suggestions on where to look at to solve this issue?
Solution: Install HTTP Activation feature
After running some more testing on other sites on the same server, I actually realised that the issue was specific to .svc files. I therefore made another search on Google and found that the server was missing the "HTTP Activation" feature (part of the WCF Services).
So, if you are having the same issue on .svc files follow the following steps to make sure you have the right components installed on the server:
Open Server Manager
In Server Manager, click the Manage menu, and then click Add Roles
and Features
In the Add Roles and Features wizard, click Next. Select the
installation type and click Next. Select the destination server and
click Next.
Skip the Server Roles page.
On the Select features page, expand ".Net Framework 4.5 Features",
expand "WCF Services" and select "HTTP Activation". Click Next.
On the Confirm installation selections page, click Install.
On the Results page, click Close.
The same can be achieved by running the following Powershell command:
Install-WindowsFeature -Name NET-WCF-HTTP-Activation45
This did the trick for me. I hope it can be of help to someone.

ELMAH does not work after moving to a new server

I made a complete copy of the old web application.
Copied it to the new server.
Made appropriate SQL Server changes and it does not work.
ELMAH Version: v1.0.3705
OS: Windows Server 2012
IIS 8
I believe I found your answer. You need to grant your IIS AppPool permission to modify (or write) to the path you have instructed ELMAH to write the XML. To do this, bring up Windows File Explorer, locate the path and folder where ELMAH is writing those XML, right click to get folder menu and select properties, locate and click on the tab labeled SECURITY, and follow the instructions described in this URL:
http://www.iis.net/learn/manage/configuring-security/application-pool-identities

ASP.NET Web Service returning Bad Request in Windows Azure

After a Windows 7 fresh restart, I open the Visual Studio 2010 as administrator, create a new project of Windows Azure Project with ASP.NET Web Role, then at the WebRole1 project I add a WebService1.asmx and press F5 (run).
The Windows Azure services starts OK and the browser open the http:/127.0.0.1:8080/WebService1.asmx perfectly. But when I click at Invoke button to test the webservice method I always receive a Bad Request - Invalid Hostname, with a http:/127.0.0.1:8081/WebService1.asmx/HelloWorld.
The most likely cause is ASMX's WSDL file doesn't stand by load balanced environment such as Windows Azure. The test feature relies on WSDL. You will see similar issues if you add a web/service reference. It is recommended to upgrade to WCF. In WCF, you can use useRequestHeadersForMetadataAddress (http://msdn.microsoft.com/en-us/library/ee816894.aspx) to fix the issue. If you need to use ASMX, please try to manually provide a correct WSDL file.

Wsdl never updates

No matter what I change in an asmx service in Visual Studio, the WSDL file stays always the same. Deleting methods, changing method signatures don't have any effect when I browse to service definition.
I have had a simular problem.
When removing an enum and replacing it by a string, the enum wouldn't go away from the wsdl. No matter what I tried (clean, rebuild, clear browser cache, other browser), it kept returning the enum as a complex type within the WSDL.
The solution in my case was remove the local folders of the project via windows explorer, then perform a get latest from TFS. After this the problem was solved.
Of course this solution only aplies when using a sourcecontrol system.
After changing your service, you must build it and ensure that the new version is running. One shortcut would be to build it (and make sure there are no errors), then right-click the .ASMX file and choose "View in Browser".
Also, although I'm sure you're aware of it, you should not be using ASMX web services for new development. Microsoft now considers ASMX to be a legacy technology. Use WCF instead.
I have encountered this problem and have a solution.
Cause: When you create a new "Web Service" project in Visual Studio, it automatically adds a "Service1.asmx" file to your project. You rename this file and change the class declaration inside of it, but Studio still thinks it's "Service1" wnd will only ever display the web service definition for "Service1".
Solution:
Delete all "bin" and "obj" folders in your project.
Copy the methods from your existing asmx file to notepad.
Remove the service from your project.
Add a new service to your project, with the name you want.
Paste the code from Notepad into the new service.
Rebuild All
Your asmx should now accurately reflect your web service and update normally on future builds.
I had today the very same issue. It was caused by a GACed version of the assembly that contained the type definitions exposed by the web service. I had to remove the assembly from the Global Assembly Cache first, like:
"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\gacutil.exe" /u YourAssemblyNameWithouthDllExtebsion /f
Be sure to restart the web server hosting the web service to reload the new version of the assembly, for example, in case of IIS Express, you can kill the former process instance by PowerShell:
(Get-Process -Name iisexpress).Kill()
After that, the updated WSDL version was displayed as expected.

Web Service application in Delphi 2007

created and deployed a Web service application in a virtual directory using IIS 6.1. The client application works fine on the same machine. But it is not working in another machine where the client application is copied manually. Can any one help what went wrong?
In Internet explorer, The XML file is displayed in the same machine. But from other machine, 'Un able to open the page' error occurs.
Suggestions please...
Regards,
Baskaran A.
Did you check your firewall settings? Can you open other pages that are served by the same IIS webserver?
My first 2 guesses would be:
1) Firewall settings, as previously mentioned.
2) The client app has a hard coded path in it somewhere that ought to be a relative path or, perhaps a URL. Something along the lines of 127.0.0.1 or localhost or C:\... within the app or in its configuration file(s).