Adding web service reference to ASP.NET Website? - asp.net

I want to add a service reference to a wsdl web service in my ASP.NET website. In Visual Studio I right clicked the project and then Add service reference. It then created the *App_WebReferences* folder with some files in it and it added some new things to my web.config.
After I moved the changes to my test server by copying the new file, the App_WebReferences folder and the changed web.config, the server tells me that I'm missing a reference for the web service. I thought it should be in either web.config or that ASP.NET should find it in the App_WebReferences folder.
I've missed something obvious but I can't figure out what. What have I missed and what do I do to get my web service reference to work on my test server?
It's working really well on my local machine.

Was this working fine locally? You need to make sure you import the service to any classes that may be using it (or Using if you are doing this in C#). Also, is the service you imported from a project that is on your pc? IF so, you will need publish that as well to the test server.

Related

Where is web.config file when running Azure web role in Compute Emulator?

I created an empty Azure Cloud Service project, then added a web role there. The role project has a web.config file.
When I hit F5 the role is deployed in Compute emulator. I went into the folder where role binaries are deployed - there's no web.config file there.
What's happening? Is that because I didn't set "copy always" on web.config file? What web.config does my role use?
If your role is configured for Full IIS mode (for those unaware of the difference between Hosted Web Core and Full IIS, see this blog post), the compute emulator should deploy the web role to IIS where it can be viewed in IIS Manager. On my machine (I'm running Azure SDK 1.5), the deployed web role's physical path is my source code directory.
I think web.config is compiled into your assembly as content in your development environment, and is not directly accessible like in staging/prod. You don't need to use Copy Always, if its marked as Content its all you need. You can use Environment.CurrentDirectory to see your web root path.
Even though the preferred way of storing configuration in Windows Azure applications is in the ServiceConfiguration.cscfg file, there are still many cases when you may want to use a normal .NET config file - especially when configuring .NET system components or reusable frameworks. In particular whenever you use Windows Azure diagnostics you need to configure the DiagnosticMonitorTraceListener in a .NET config file.
When you create your web role project, Visual Studio creates a web.config file for your .NET configuration. While your web application can access this information, your RoleEntryPoint code cannot-because it's not running as a part of your web site. As mentioned earlier, it runs under a process called WaIISHost.exe, so it expects its configuration to be in a file called WaIISHost.exe.config. Therefore, if you create a file with this name in the your web project and set the "Copy to Output Directory" property to "Copy Always" you'll find that the RoleEntryPoint can read this happily. This is one of the only cases I can think of where you'll have two .NET configuration files in the same project!
All info is from Azure Team Blog and I have used this solution successfully- http://blogs.msdn.com/b/windowsazure/

HowTo Web.config transformation in VS 2010 IIS Website without creating a Web Application Project?

I would like to use web.config transformation but do not see the "Add Config Transforms" in the context menu when i right-click on my original web.config file.
I do not have a Web Application Project and cannot have one. My solution has a few projects for BLL, DAL etc, then i have a local IIS website for the main Website.
Under my local IIS website i have a web.config and have tried to add a web.Debug.config like such:
How can i do web.config transformation using the localhost IIS website and not having to creating a Web Application Project? Is it even possible? Is creating a Web Application Project a requirement?
I was recently reading up on this subject and to my knowledge you can not do web.config transformation in a Web Site project for one simple reason – Web Sites don’t have project files, which is where the msbuild configurations are stored. So if you need that functionality you will have to create a project file. But have a look at this blog which I think gives a better explanation for this.
http://andrewtwest.com/2010/02/25/using-web-config-transformations-in-web-site-projects/
Having said that if you do find out that im wrong, which i might be please keep me updated with what was your solution
Thanks

ASMX Web Service online works when all of the code is in one file without code-behind

I have an ASMX Web Service that has its code entirely in a code-behind file, so that the entire contents of the .asmx file is:
<%# WebService Language="C#" CodeBehind="~/App_Code/AddressValidation.cs" Class="AddressValidation" %>
On my test machine (Windows XP with IIS 5), I set up a virtual directory just for this ASP.NET 2.0 solution and everything works great. All my code is separated nicely and it just works.
However, when we deployed this solution to our Windows Server 2003 development environment, we noticed that the code only compiled when all of the code was dropped directly into the .asmx file, meaning that the solution didn't work with code-behind. We can't figure out why this is happening.
One thing that's different about our setup in our development environment is that instead of creating a separate virual directory just for this solution, we dropped it into an existing directory that runs a classic ASP application. So here we have a folder with an ASP.NET 2.0 application within a directory that contains a classic ASP application. Granted, everything in the ASP.NET 2.0 application works if all of the code is within the .asmx file and not in code-behind, but we'd really like to know why it's not recognizing the code-behind files and compiling it correctly.
As others have mentioned, it's probably a better practice to build the solution as a "Web Application Project." This way your code will be precompiled to run on the server.
The following solution worked for us: In IIS, navigate to the folder in your website that contains your solution. Right click on the folder and choose Properties. In the Directory tab, under Application Settings, click Create to make the folder into an application (I believe this can also be accomplished simply by making the folder a Virtual Directory). Then, make sure your ASP.NET configuration is set to use ASP.NET Version 2.0. The problem we had was that the larger directory was running under ASP.NET 1.0, so we had to go through this step to have this directory use ASP.NET 2.0.
You may have a difference between a Web Site "project" and a Web Application project. In a web site project, all of the files are compiled dynamically. In a web application project, you have to build the code first.
You should be using Web Application Projects for web services. Use File->New Project and choose the appropriate project type. Then build your project and finally use the Publish command to deploy to IIS.
I'm not sure I can explain why its not working however placing Code behind files in the App_Code folder seems like a dodgy thing to do. App_Code files will get compiled into a single assembly. Hence the code in your code behind will end up in this assembly even though its not intended to.
I would first create a AddressValidation.asmx.cs file in the same folder as the .asmx folder and tweak the CodeBehind attribute of the asmx file. Remove the file from the App_Code folder and place its contents in the new .asmx.cs file.
Check this works in the XP environment then move it the destination server.

Problems consuming webservice on ASP.NET on production(IIS) server

We've implemented some SOAP client code on our ASP.NET site that calls up a remote service. Implementation was basically done by using Visual Studio "Add Web Reference" wizard, adding proper 'using remote.service.namespace' to the code and calling the service.
Code works perfect locally(from Visual Studio), but fails on production web server with missing assembly reference error:
CS0246: The type or namespace name 'remote.service' could not be found (are you missing a using directive or an assembly reference?)
I have a sneaky suspicion that I am not deploying everything properly, maybe some one can point out what is that I am missing there?
Thanks!
Additional info:
Project is a Website.
ASP.NET version 2.0 installed and used as a target on both dev box and production server.
Proxy file generated by WSDL.exe is deployed into the root folder of the website, same folder where the page resides. Global namespace(default) was used for proxy class generation.
If this is a WebSite project, then the proxy file should reside inside the App_Code folder
You mentioned the proxy dll is placed on "the root folder of the web site, where the page resides".
You should place the dll inside the "bin" folder. If the folder is not there create it.
The Web Service client stack in .NET does runtime generation of the proxy client (from the annotations in the class generated by wsdl.exe/svcutil.exe). this generated file typically ends up in one of your servers temp directories (there's one under the main windows tree somewhere). The problem is that the ASP.NET user account doesn't have rights to write to this particular temp directory, but doesn't notice at the time it writes the file, so you end up with an error with it trying to load the generated file back. You can end up in the situation depending on the exact installation order on your server. Once you find the right directory you can simply fix the NTFS perms on the directory to solve the problem.
Did you copy the App_WebReferences folder and all its contents to the server?
Does other parts of your ASP.NET site work?
Does your site target 3.5 and possibly 3.5 is not installed on the production server?
Is this a Web Site, or a Web Application Project? I bet it's a Web Site.

Problem Importing Web Service

I have created a web service in a virtual directory using VS 2008. I have tested the service by going to the .asmx page and everything is working fine. So I selected the "Add web reference" option under the solution and typed in the .asmx URL. It found the web service successfully and added the reference to the project. However, when I try to import the service namespace using the same name as the directory under the "App_WebReferences" folder, it doesn't recognize the name and gives me an error if I try to import it. Have I missed any steps in the process?
Update: Try generating the proxy manually using the wsdl tool and adding the proxy class as an existing item to client web application project as mentioned in the link.
Something strange happening with proxy generation in your case from VS. Maybe an access issue.
If it happened fine, you should be able to find the VS generated proxy class under one of the sub-folders of
%windir%\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ (for Asp.Net 2.0). Search for file names starting with App_WebReferences*.cs in the temporary folder.
When you added the web service, what is the name of the web reference you gave? Use the same web reference name in your import statement.
In this link, web reference name is com.deepfitness so you can import com.deepfitness namespace in your asp.net app.
To be absolutely certain click view all files in you web project and follow your reference in App_WebReferences down until you get to reference.cs open this and you can see the correct namespace.

Resources