ASP.NET Web Service - Log SOAP XML - asp.net

I have an ASP.NET asmx web service running on IIS.
A client is trying to consume the service, and I can see (after a rebuild) that the Global.asax Application_Start is getting hit from his attempt... but the specific function is not getting hit.
This link
Getting RAW Soap Data from a Web Reference Client running in ASP.net gives a "solution" for what I'm trying to do, but it didn't work.
I placed the above link's suggestion in my web.config, but no log file is generated even when I successfully call the service myself.

If you're looking to trap request/response on the client side, you can connect to ASMX webservices using WCF-style generated proxies just by using a "Service Reference" rather than a "Web Reference", then follow the WCF tracing you linked to for raw data, as well as using System.ServiceModel.MessageLogging for SOAP-specific stuff. Keep in mind that:
the maxdatasize attribute for System.Net will truncate the data logged, so pick a bigger number if your request/responses are larger. Use maxSizeOfMessageToLog with System.ServiceModel.MessageLogging.
remove the raw ascii/hex and only show the xml with tracemode="protocolonly" in the <source name="System.Net"> element
But if you want to trap requests on the server side (i.e. from within your ASMX webservice) you can try the suggestion here, which is to just read the data out of the request stream in Application_BeginRequest and probably also the response stream in Application_EndRequest.

Related

SOAP and HTTP Services within the same ASP.Net Project

I have an existing web service project that is using SOAP messages to communicated back and forth. I have just created what should be an HTTP service called "AJAXWebServices" that has an attribute over the service class of "[System.Web.Script.Services.ScriptService()]". I want this service to utilize HTTP POST/GET and the other services in the project to continue utilizing their SOAP. The AJAXWebService works fine if the ".asmx" file is in the local project but when I publish it and then make a web reference to it, and I set the service path of my ajaxToolKit:AutoCompleteExtender to "HTTP://server/folder/AJAXWebService.asmx" the page loads and when I start typing it will make the request but return an entire page of HTML instead of just the autocomplete words. It freezes my I.E. while its parsing all the XML. What can I do to fix this?

find which server in a web farm the web method got executed?

This question is a consequence of the following question: determining which server (in a web farm) the asp.net ajax request came from?
The problem is that we commonly use automatically generated proxy classes to communicate with the web method (which may be part of asmx/wcf service). When we receive the response from the web services server, how do we know which server it got processed from?
We receive the response from the server side code which is executing (mostly). When its a script service (which can be called via javascript) its another case altogether.
How can we read the response headers once the web service returns?
Am I constrained to build my own proxy classes to solve this problem?
One way. Its not the best way but it will do until something new comes about. If you have a tool like fiddler/burp, you can inspect the response headers. So we must configure the IIS to set the response headers appropriately.
By default they are configured to output something like X-ASP.NET...a good idea would be to add the server name to that...

How to show soap request xml for a web service call?

I am using a web method of a company's web service.
This web method requires one parameter when calling it:
CompanyOpereations srv = new CompanyOperations();
srv.getCustomerInfo(input);
How can I see my soap request xml when calling this method?
How do you want to see it? If it's inside the code; I don't know. (Un)Fortunately .NET does a pretty good job of hiding it for the developer.
However, if you just want to debug the calls and nothing else: try Fiddler. It will show you the Request/Response (including headers and everything else) for the webservice calls. This is what we use for debugging webservices. But you can use it for everything that uses the HTTP protocol for communication.

Accessing IIS's request handling pipeline to inject a request and get the html response

Is it at all possible to inject a request into IIS for a page, have IIS and ASP.Net handle it as normal, but get the response as html handed back to me programmatically?
Yes, I know that I could connect to port 80 using WebRequest and WebResponse, but that becomes difficult if you are accessing the IIS server from the same physical machine (loopback security controls et al).
Basically, I want to inject the request (eg for http://example.org/MyPage.aspx) between the points at which IIS would normally talk to the browser, and the point at which it would route it to the correct ASP.Net application, and get a response back from IIS between the points at which ASP.Net/IIS applies the httpfilters and hands the html back to the browser.
I'm predominantly working with IIS7 so if there is a solution that works just for IIS7 then thats not an issue.
You could implement a custom HttpModule, which would give you access to the IIS pipeline, including the final response. However, you would still need to initiate a request to IIS to actually kick off processing. Not sure if this would work for you.
From the MSDN documentation:
An HTTP module is an assembly that is
called on every request that is made
to your application. HTTP modules are
called as part of the request pipeline
and have access to life-cycle events
throughout the request. HTTP modules
therefore let you examine incoming
requests and take action based on the
request. They also let you examine the
outgoing response and modify it.
Gave you looked into the WebCkiebt class? You can make the request and get the response HTML.
http://msdn.microsoft.com/en-us/library/system.net.webclient.downloadstring(v=VS.100).aspx

Receive requests with a .asmx file or a .aspx file?

I'm setting up my site to receive info from people via text message. The way it works is they text a number, that service then sends an HTTP POST to a url I specify. I've heard that .asmx files are better than .aspx files because they don't go through the whole page lifecycle. However, I don't really understand how to get a .asmx file running, and can you even call it with a POST, ie, www.mysite.com/webservice.asmx? I know I can make it work with a .aspx file, but I wanted to check to see if there was a better way before I undertake this endeavor.
Thanks for your insight!
While any extension can be mapped to any handler in ASP.NET, by default .aspx is mapped to page handler and .asmx is mapped to Web service handler. I think you are looking for .ashx which represents a generic simple handler. You just need to implement ProcessRequest method of the IHttpHandler interface after adding one to your project (Add New Item -> Generic Handler).
The .ashx works well if you want to manually process the request. Only if you want to provide a Web service (e.g. SOAP), you should go with .asmx. As a consequence, the best solution depends on the format of the HTTP POST request they send. If they send raw data in POST with their own specific protocol, go with .ashx. Otherwise, if they are using a standard RPC (SOAP, XML-RPC, ...) protocol, .asmx is probably better.
Create an .asmx file with Visual Studio. It should create a template with a HelloWorld method. Browse to it with your favorite browser and you'll actually get an explanation on how to post requests to it using various methods.
There is another type you haven't mentioned: ashx. However, in your case, a webservice (asmx) would make sense.

Resources