WCF using it's own web.config - asp.net

I have a MVC3 app that is calling a WCF Service Application. The WCF Service App has its own web.config file (comes when you create the project automatically). In this .config I added an appSetting section with key to retrieve.
When I run the MVC app and it calls the WCF svc and the svc cannot see this appsettings value. If I move the appSettings section over to the MVC web.config the service application sees the value.
I would expect this from a calling application if it were a Winform or client based application calling a DLL but not where I have 2 separate apps where I actually want separate configuration files.
For example, I want to configure unity in my web services to perform dependency injection. I don't want the calling web application to know or have to define these values. The service should have them.

The issue I had was with the Unity configuration in the MVC app. Originally I had been pointing at a class library for my services layer, I swapped this over to use WCF. When I did this I left in the old type registrations which unity resolved and caused it to look at the new WCF project (same namespaces/class names) as a class library instead of using the endpoints that I registered.
Ripped out those specific class registrations leaving just the interfaces and endpoints and it worked like a charm.

Related

Using a WCF Reference in a DLL used by Classic ASP

I created a .NET DLL library which is COM-visible for the Classic ASP to use. I referenced a WCF service in the library and whenever I try to call the DLL from the classic ASP, I receive the following error:
Could not find default endpoint element that references contract 'ContractName' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
Now, I set the reference to be internal access level. I noticed that VS created a DLL.config file with the service endpoint information, so I put the config file in the assembly folder for this DLL, but no luck.
Any idea how to use WCF endpoint reference?
SOLVED
All I needed to do is to create a BasicHTTPBinding and provide an endpoint address on the fly.Then create a new instance of the web service using the created binding and endpoint address.

Why is a Service Reference required in web application in addition to the class library that uses the service?

I am intending to provide access to a web service for an ASP.NET web application through a class library, and have been experimenting with a simple weather service.
In case it makes a difference I am using Visual Web Developer 2010 Express.
The interface between the web application and the class library is a simple string passed and string returned to a single method of a single class e.g.
String forecast = LibClassInstance.GetForecast("Madrid");
I added the Service Reference to the class library using AddServiceReference and created my call to the service through the automatically generated proxy classes. So far so good.
I then went to call my simple GetForecast method from my web application and got a long error message to the effect that the service might not have been configured in my project's Web.config file. After adding the Service Reference to my application project as well, it all worked as expected. I was hoping that the service behind the class library code would be hidden from its clients.
Can anyone tell me why it was necessary for me to add a service reference to the web application as well as the class library in order to get it working?
Can anyone tell me why it was necessary for me to add a service reference to the web application as well as the class library in order to get it working?
It isn't necessary. But you do need to configure the service in Web.Config - as a starting point you can copy the system.serviceModel section that was generated in the app.config of your class library when you added the Service Reference.

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.

How to reference web service with my asp.net application

I have my own web service application with more then one .asmx file.
Now i am not getting how can i reference web service with my web application as "Add Web Reference".
I want to connect with both asmx files at once.
Means once i connect web service as add web reference and i can call both .asmx file from my code behind page.
Doesn't work that way. You have to reference each web service or consolidate them.
You could do this:
Invoking Web Service dynamically using HttpWebRequest
When you add a web reference to your application, Visual Studio creates a proxy class that you use to connect to the web service. You will not connect to the web service directly. The proxy class name is set when you add the reference. It suggests a name for you that you can change.
As long as you are using the proxy classes that are generated, you should be able to connect to as many web services as you desire.
I hope that helps.

Is this the way I should deploy a asp.net application

I have a solution containing
asp.net project
class library
WCF service class library
WCF service application
I've added a project refference from the asp.net project to the class library project and to the service class library project.
I've published the asp.net application, loaded it to the webserver root. all ok.
Now for the service, I've created a new folder on the root called WCF, and placed the aplication in there.
Is this The way I should deploy the sollution? Are this the steps when you have more than a simple asp.net application?
PS: How do I change that WCF folder to make it an application trough a control panel because I get this:http://surveillancecamera.somee.com/WCF. The reason why I get this is described here:
I would treat the WCF service as a separate entity altogether. Deploy the WCF service and verify it works, then deploy the ASP.Net application.
WCF services have a different set of configuration rules that don't always pair nicely in the same "application root" as your ASP.Net web application. In addition, you may want to use the same WCF service in different applications, and it may not be accessible if it is tightly coupled to this ASP.Net application.

Resources