Problem Importing Web Service - asp.net

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.

Related

Adding web service reference to ASP.NET Website?

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.

ASP.NET - Change from Web Application Project to Web Site Project

I am new to Visual Studio and ASP.NET. I have a MyClass.cs file under App_Code directory, but could not able to run the function in the class file. Keep getting this error:
The name 'MyClass' does not exist in the current context
I know that code works fine since I posted the codes and others confirmed it works, but I am still receiving the error above.
I read alot more threads on the NET and somes indicated that problem is using Web Application Project instead of Web Site project, which the class file would not compile. I am not sure if I've created it under Application Project we Web Site project.
How can I tell that my site is running under Web Application Project or Web Site Project? and How can I change it to Web Site Project so my class can be recognized.
Thanks in advance,

how to access webservice from one project to another project

i have an project with name called(dbservice layer) which is in path: d:\webservice\DBService. here i have an webservice which connects to DB and returns an object of an class.
once i added an reference here i get an url:http://localhost:2371/Jobs.svc
now i have another project name (UILayer) whic is in path: E:\School\UILayer
i added an service reference here with url as http://localhost:2371/Jobs.svc
but i get an messgae telling service is unable why is that happening.
if both my webserivce layer and ui layer are in same project. then i able to use the webserive in the ui layer. and get the required output
so i wanted to know is there any way we can acesss the webserive from one project to another project
thanks in advance
prince
Publish your web service to an actual location and then add a reference using the actual URL not the one served up by visual studio. What I think is happening is each Visual Studio instance is using a different port so you can't say localhost:2371 for both projects because that is the local port for the instance your running with your original project.
Publish it and then access it via http://localhost/jobs.svc. You should be able to access it via IE directly without running Visual Studio if you have published it correctly.
The main point is, you have the wrong URL.

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.

ASP.NET solution with class library project

I have an solution in VS 2008 which contains two class library projects and an ASP.NET web site. The ASP.NET site references the class libraries and one of the libraries contains a LINQ To SQL item.
My question is with regards to the app.config in the class library which contains the connection string for the database. When I build the project, this app.config isn't within the build directory and this means I can't dynamically change the connection string for the deployed project.
What am I doing wrong here, how can I have these settings deployed too so I can make changes to the connection string?
Thanks in advance,
Martin.
This caused me a bit of confusion at first as well.
You might think that the class library uses the app.config file that's contained in it's own project but it doesn't. It uses the config file of the project that is referencing it.
So what you need to do is look for the <appSettings/> tag inside the web.config file of your ASP.Net project and change it to <appSettings></appSettings> And add the <add ... /> tags that are contained in the app.config file of the library project. You don't need to change anything in your code for the ConfigurationManager class to figure this out. It knows where to look automagically.
Hope that makes sense.
You can edit the Web.config file in the final product. Configuration APIs normally will get configuration data from the primary configuration file of the application which, in case of ASP.NET apps is the Web.config and for client applications is Myfile.exe.config. It's important to know that class libraries in the project usually will not have their separate configuration file like MyClassLib.dll.config (unless you manually refer to the specific file).
To overcome the problem of connection string, here is the trick
Inside ur class library declare module that has got two properties, one is a setter and the other is a getter, and make them public.
Inside ur website project, go to the global file, and under both session start and application start call the setter property that u declared previously, and assign it the connection string that is located in ur web.config, now the connection string will be available in the website general scope and the value exists as long as ur session credential not expired.
Copy the connectionString section from your library's app.config file to your web.config file. Change the actual connection string from your development to your production server as necessary. The ConfigurationManager class that LINQ2SQL uses to obtain the connection string will look in the web.config file for the appropriately named connection string and use it if it exists.
If you want to have different settings for development vs production, use the Web Deployment Project. Download here. From Microsoft's description:
Visual Studio 2008 Web Deployment
Projects provide additional
functionality to build and deploy Web
sites and Web applications in Visual
Studio 2008. This add-in provides a
comprehensive UI to manage build
configurations, merging, and using
pre-build and post-build tasks with
MSBuild.

Resources