How to debug a web service in Visual Studio - c#

I have to make some changes to a Web Service which is currently in production.
There is a project (a class library) called Accounts.WebServer which is a container project, it's Global.asax initializes a WCF service as an instance of the web service class.
My question is how can I run the web service (container project or project containing the web service) locally? I try and run the container project through VS2015 and I get a lot of IIS errors, one I fixed by adding
<validation validateIntegratedModeConfiguration="false"/>
to the web.config
But I am still unable to get the web service to run. Once it is running I should be able to see a page which lists the operations exposed, and see sample data to pass to the operations.

Related

"Hot-Swapping" Web Service References in Visual Studio

I've recently written prototype code that consumes a commercial web service that is hosted on ServerA.
I've added the reference through Visual Studio, written some code that calls a few exposed functions from the service and everything works great.
I'm now trying to change the reference to that web services to another URL, to target another server, ServerB. I BELIEVE the services on these two machines are the same.
However:
ServerA runs some version of the application which includes the deployed web service.
ServerB runs a different version of the application which includes the deployed web service.
Both WSDL contents are identical, the namespace addresses between the two are identical (the target namespace URLs are the same[note that the URLs both reference an external address e.g. http://google.com/services/whatever/]), but my prototype code only works when I reference the web service from ServerA.
I throw a "Fault occurred while processing." exception whenever calling an exposed function on ServerB. From my understanding this is an unhandled exception that is thrown server-side and it does not give me much info to debug.
If these web services were truly identical, would swapping out the endpoint URL in my application configuration be enough to switch references between the two web services or am I grossly misunderstanding something?

Combining WCF Service Library and WCF Service Application

Thanks to Stack Overflow and a few other sites, I understand the difference between the WCF LIbrary and WCF Service Application templates.
Briefly the Library is a DLL that allows for multiple types of hosting. It does not have a .svc file. While the Service Applications template is created specifically with IIS in mine with a .svc file.
I read that WCF Service Library is the best way because it is the most flexible. But I NEVER see instructions on how to do it apart from using the WCF Service Application template.
Is it difficult to go from WCF Service Library to hosting on IIS from scratch? I have two books on WCF and I've read numerous articles and none of them cover how to create a svc file using only the WCF Service Library and No WCF Service Application. Why?
Nigel Shaw also mentions on the following link that there are limitations to using the Library option. What is the purpose of WCF Service Library?
Basically What I want to do is host the WCF Service on both IIS and a Windows Service. Thus it appears that the combined way is the best way. Nevertheless, I'm trying to learn why there aren't more instructions on using the WCF Service Library.
Ok, I did find a couple of articles that seem to use an ASP.NET Web Application and tells you how to create a text file for the svc file.
This article: http://debugmode.net/2010/12/25/wcf-service-library-creating-hosting-and-consuming-wcf-service-with-wcf-service-library-project-template/
and this one: http://danielvanwyk.wordpress.com/2010/04/30/create-host-and-consume-a-wcf-service-using-the-wcf-service-library-template-in-visual-studio-2008/
But what I still don't understand is why is the ASP.NET Application still needed? And If i add a svc file does it get placed in the wwwroot directory (that seems to be where the WCF Service Application places it .svc file?
Thanks!
A WCF Service Library has to be hosted in order to be used - you can host it in IIS, a Windows Service or some self-hosted option (like a console app, WinForm, WPF, etc).
In the last two links you provide, they're demonstrating how to host the library in an ASP.NET service application, but you don't have to use that project template to host it. It's simply one option out of several.
You can create an IIS-hosted implementation of your class library without using a VS project template, but you'll need to manually add the .svc file and the Web.config. I have done this several times:
Create a folder (I normally put mine in the wwwroot folder of inetpub, but you can put it wherever you desire).
Create a bin folder in the folder you created in step 1, and put the WCF service library and any other required assemblies in it.
Add a .svc file with the appropriate markup in the folder created in step 1.
Add a Web.config with the appropriate service model configuration in the folder created in step 1.
Create an application in IIS that points to the folder you created.
Now you have an IIS-hosted instance of your service. You can then use another copy of the WCF service library for your Windows-Service hosted instance.

Solution with web project and web service deployment to azure

I have one project solution in which I have one web project and another project is service. Now if I run it locally, it is working fine without any problem but when I deploy it on to cloud (azure specifically), its looks up and starts running but moment it tries to access the service which is used for log in mechanism it is showing an error.
As I don't know how to trace it on to azure, I'm unable to find actual root cause of it.
While publishing it to azure, I have just marked my main project into web role. Do I need to add anything else in web role node while deploying package to azure?
To perform diagnostics during development, one useful technique is to activate Remote Desktop on the cloud instance and connect to the server to check the event logs for errors.
If you have Visual Studio Ultimate, you can also use Intellitrace to collect debugging information on the published cloud service. See Debugging a Published Cloud Service with IntelliTrace and Visual Studio.
You can also debug locally using the emulator. See Debugging a Cloud Service in Visual Studio.
As for your project architecture, you have a few alternatives:
Add a web role for each project; i.e., one web role for the web project and another web role for the service project. This will create two instance groups, and one of this roles will be assigned the TCP port 80; the other role will be assigned another port such as 8080.
Add both project in a single web role as distinct web sites. See Configure a Web Role for Multiple Web Sites, Tips for Publishing Multiple Sites in a Web Role, One Azure Web Role, Multiple Websites.
Reorganize your solution so that you have a single website project that also has the service definitions, and keep the service implementation in a separate class library project. This way you would have one web role and one web project with both the website and the services.

Use WCF class library in application

I am new to WCF and I don't really understand the puropose of a WCF class library. (it does not look like a library to me it launches a program when I run my application) I have created a WPF application with a reference to my WCF service library. Everything works great under development. When I launch my application from visual studio the service get's hosted automatically by visual studio.
Now let's say I am ready to deploy. If I launch the application from outside visual studio then the service will not run. How do I start the service?
WCF service class cannot exist in a void. You need to host and there are a couple of option for Hosting.
In Visual Studio, there was two main template for WCF, WCF Service Application and WCF Service Library. Depend on your need, choose which template will be good for your project. If you want Self Hosting, better choose WCF Service Library template. (You need to write Hosting Service/Application). If you want to Host in IIS, better choose WCF Service Application.
And check this Tutorial for self hosting.
http://wcftutorial.net/WCF-Self-Hosting.aspx

Get Webservice WSDL in different project within same solution

I have a Web Service Project and a Web Site Project both within the same solution. I have a simple link on a web page within the Web Site Project that needs to point to a web services WSDL (example: Webservice.asmx?WSDL) within the Web Service Project. Is this possible?
Would I be better off using a hardcopy of the WSDL document and just putting that in my web site project?
I don't believe so. You will need to have the webservice run, in either IIS, or through visual studio.
Why not add a Web reference to the Webservice (Browse for "Web services in this solution") ?
That's what adding the reference does, basically... along with creation of the class mapping. Then you could always update references without having to worry about hard coded wsdl links.

Categories

Resources