Debugging WebMethod()s - stepping into code from the calling project - c#

I used a decompiler to retrieve lost source code for a set of web services written long ago. I want to debug the retrieved web methods using an existing web forms project. The two projects my solution contains are: 1) The recovered web services project and 2) The calling web forms project (created years ago) that references the live web services.
I created a project reference from the web forms project to the new web service project. My goal is make temporary changes in the calling code to allow me to step into each WebMethod using the project reference instead of the live web service reference. I'm hoping to debug the WebMethods as if I was debugging a standard class library.
The problem is that none of the WebMethods are visible using the project reference. Only the containing class is visible in the calling project but none of the Public Subs or Functions show via intellisense. How can I debug these WebMethods using the existing calling code from the web forms project?
Here is one of the simpler calling routines:
Private Sub LoadCountryCode()
Dim liveWebService As New EPriceBookWebService.Service1SoapClient
'Next line TEMPORARILY commented out for testing...
'liveWebService.GetCustomerCountry(lstbxCusCodes.SelectedValue, _countryCode)
'Project reference below shows only the web service class, not the contained public methods via intellisene. WHY?
EPriceBookService.EPriceBookService.
End Sub
Here is the stub of the WebMethod() being called:
<WebMethod()>
Public Sub GetCustomerCountry(ByVal CusCode As String, ByRef CountryCode As String)

I'm answering my own question here...
It was unwise for me to use a project reference to debug a web service project. Instead, I've learned how to debug the web service project from the calling web forms project (directly stepping into the code). To do this I made use of an obscure setting in the web service project called "Don't open a page. Wait for a request from an external application." You can turn on this setting from the project property pages under the Web category. I learned about the setting here and here.
My two projects are in the same solution. The web forms project now references two web services 1) the live web service and 2) the localhost web service in my solution. I've added compiler (preprocessor) directives to the web forms project telling it which web service reference to use.
#If DEBUG Then
Dim theWebService As New localhostEPricebookWebReference.EPriceBookService
#Else
Dim theWebService As New EPriceBookWebService.Service1SoapClient
#End If
Be sure you turn off debug mode before deploying your application.

Related

Successfull build but runtime error on Web Application converted from Website Project

I am trying to convert a big website project to a web application project. The project was fine as website project but after i converted it into a web application project it started to give "Object reference not set to an instance of an object."
I resarched web for the convert proccess. Firstly i created an Empty Web Application. Then i gave the required referances to the new application and copied the old files to new project. I build again and select the Convert to Web Application.
The error occured when i tried to start, which is this
I thought it was from some global asax related issue and searched. I saw that i can't add global asax to a converted website and i moved the converted project to a brand new web application. I added the global asax, modified and build successfully but again, when i started the project it gave me the exact same error.
I followed it through a breakpoint. No problem with application start but it explodes on beginning of session start.
Can you please help me on this?

MS Azure - C# WebJob Project Dependency

I am new to Azure WJs. I have 2 projects in one solution: the actual website - Project 2 and the WebJob - Project 1. The only task the WJ has is to call an exposed method from the public class of project 2 during the scheduled time.
When the WJ was created, the classes & methods of the Project 2 - website were added as a solution reference to the Project 1 - WebJob to make them accessible.
The problem I have is:
When the WebJob is build it compiles all the dependencies at the given time. When the final .zip is uploaded into Azure WebJob portal the webjob will execute with the compiled code version. This means that any new changes to Project 2 - website do not take effect until the WJ is re-build with the updated Project 2 - website dependencies and the .zip re-uploaded.
Is there a way to create WJ (as Project 1) which would call a specific exposed method from the Project 2 and be oblivious to the changes in the project 2 as long as the called method is present?
Example:
WebJob Code (project 1):
namespace SecondProject
{
class Program
{
static void Main()
{
var client = new WebClient();
secondProjectMethod();
}
}
}
Website Code (project 2):
namespace firstProject
{
public class someClass
{
public void secondProjectMethod()
{
// I want to make any code changes I want inside this
// method anytime and the WbJob should not care
// about these changes as long as this method name exist.
// Because all it should care about is that it should
// call this method name.
}
}
}
Since you are using a website, you can expose the method from Proj2 as an API, and make the WebJob invoke the API (instead of the method) at your scheduled interval. So even if you change the method in Proj2, as long as the exposed API is calling the updated method the WebJob will be independent.You can take a look at this link, for creating a basic API
at least two options come up in my mind:
Options 1: your WJ project do not directly reference your website project, instead, use reflection load the website dll in runtime. and use reflection to invoke the function you would like to call (assume signature will never change)
the challenge for this approach is your WJ somehow need to figure out the path to the website dll.
Options 2: since it is a website, why not expose the function you will like to call as a REST API, so your WJ just need to make a http call
The question doesn't seem to be a Web Job Specific one but anyways...
If you need the two projects to be independent, then you should not be using project references.
What I would suggest is to publish the Project2 shared class/methods as nuget packages and use the nuget instead, so any changes to the Project2 will not affect your WebJob until the point that you publish a new nuget package and use that your web job.
Alternatively you can have a folder for your dlls like "Shared Libraries" and reference the Project2 from that location instead of project to isolate the changes to your Web job from your Project reference..

how to define url path to access child projects from main project

I have 3 projects- Main Project, Project A and Project B. I have added reference to both A & B inside Main project. Now, if i make ajax call from Main project to say Project A (web service project), how would my url look like? I have tried using localhost, but i ran into CORS issue. So, is there any solution for that? thnks.
var url = '../ProjectA/someService.asmx?op=Action';

Multiple Web Projects in a single ASP.NET Solution

Is it really possible to have a two different asp.net web projects in a single web solution ? For instance here's the current structure
+Solution
-CoreModule
-CustomModule
-WebProject
In this same hierarchy, can I have this
+Solution
-CoreModule
-CustomModule
-WebProject
-NewWebProjectModule
And use the web pages defined on NewWebProjecModule inside WebProject and use the style defined in WebProject inside NewWebProjectModule ?
What I am trying to do is separate the modules in the web project to have less clutter ?
Or would I be better of doing a control library as different project OR have the business rules on a separate module and have the UI on the main web project ?
First, you can very much have more than one web project in a Visual Studio Solution. While debugging with VS, you will have to run the required one.
If you have contents/controls that get replicated/reused in both web projects, I would prefer to have them in a common library/module and use them as required.

Implement mock service with wsdl tool

I'm currently following this tutorial to learn how to implement a mock web service:
http://iandykes.blogspot.nl/2008/06/creating-mock-web-services-in-net.html
The web service that i'm using is a public web service: http://www.webservicex.net/CurrencyConvertor.asmx?WSDL
So i used the wsdl.exe tool to generate a class for that service, like it is explained in the tutorial. I also added the generated .cs file to my Solution project.
I then did the following in Visual Studio to add the Web Service:
Right clicked on my project -> Add Service Reference -> Advanced -> Add Web Reference
In there i added the URL to the web service and then hit the Add Reference button. So now i have a Web References folder in my project with a CurrencyProxy in it (that is how i named it).
The next step that i have to do according to the tutorial is:
In the code behind for this Web Service, change the class definition
so that it implements the interface in the generated code.
That is where i'm actually stuck. Where can i find the code behind file of the Web Service? I'm not sure what to do here.
Could anyone help me out?
When you add Web Service to your project, there will be YourWebService.asmx and YourWebService.asmx.cs under it. In YourWebService.asmx.cs, just replace System.Web.Services.WebService with your interface, which was generated earlier. Implement this interface as you wish and that's it, mock service's done.

Categories

Resources