Using Fiddler to troubleshoot classic asp file calling web service - web-services

I am having trouble debugging a classic asp file in which I call a .NET web service. I am hoping that I can use Fiddler to see why the HTTP request to the web service is returning a 'Bad Request' error. I have a console application to request the classic asp file. Within the classic asp file I call the web service. When I run Fiddler, I see the request to the asp file but not the request to the web service. There is just one line in Fiddler with the asp file request.
Any suggestions or advice to troubleshoot the asp file would be appreciated.
Below is the code to sends a GET request to the web service.
The response in the console application is:
Status: 200
Status text: OK
But the call to the web service does not appear in Fiddler, only the call to the asp file. The web service and asp file are on different servers.
Shouldn't I see this call to the web service on Fiddler?
I want to debug a POST request but first I must learn how to use Fiddler. :)
This is my console application that calls the asp page:
Uri aspPServiceUri = new Uri("http://<serverNameAndPath>/FirstPage.asp?<parameters>;");
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(aspPServiceUri);
httpWebRequest.Method = "GET";
HttpWebResponse resp = (HttpWebResponse)httpWebRequest.GetResponse();
Stream resStream = resp.GetResponseStream();
StreamReader reader = new StreamReader(resStream);
string strResponse = reader.ReadToEnd();
Console.WriteLine(strResponse);
reader.Close();
This the asp file:
Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
URL = "http://<serverName>:<port>/PService/PService.Paging.svc?WSDL"
httpRequest.Open "GET", URL, False
httpRequest.Send()
Dim strResult
Dim strStatusText
Response.ContentType = "text/xml"
strStatusText = "Status: " & httpRequest.status & vbCrLf & "Status text: " & httpRequest.statusText
Response.Write(vbCrLf & strStatusText & vbCrLf)

Assuming you are using IIS 7+ or a relatively recent version of IIS Express, add the following to your web.config file. If you don't already have a web.config, then add one.
<system.net>
<defaultProxy enabled="true" useDefaultCredentials="true">
<proxy autoDetect="False" bypassonlocal="False" proxyaddress="http://127.0.0.1:8888" usesystemdefault="False" />
</defaultProxy>
</system.net>
This configures Fiddler as a proxy, so all HTTP requests from the web app will be routed through Fiddler.

Related

web service call from classic asp page does not return string but does not fail

I am trying to call my .NET web service from a classic asp file. I have to update the asp file to connect to a new web service. This asp file is called by a 3rd party application and it pages a user. I created a .NET console application to test this .asp file to simulate the 3rd party application's use of it. The console application runs locally.
When I run the console application, that runs the new version of the asp file that connects to my web service, there are no errors until I try to display the return result from the web service. I suspect my SOAP request is incorrect.
The web service method is called 'TestMethod' and has no parameters.
This is the URL of the web service: 'http://:/Service1/Service1.Paging.svc'
This is my asp code:
Set httpRequest = Server.CreateObject("MSXML2.ServerXMLHTTP.6.0")
URL = "http://<servername><port>/Service1/Service1.Paging.svc/"
httpRequest.Open "POST", URL, False
httpRequest.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
httpRequest.setRequestHeader "SOAPAction", URL & "TestMethod"
Dim strSoapReq
strSoapReq = "<?xml version=""1.0"" encoding=""utf-8"" ?>"
strSoapReq = strSoapReq & "<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/"">"
strSoapReq = strSoapReq & "<s:Body>"
strSoapReq = strSoapReq & "<TestMethod xmlns=""http://<servername><port>/Service1"">"
strSoapReq = strSoapReq & "</TestMethod>"
strSoapReq = strSoapReq & "</s:Body>"
strSoapReq = strSoapReq & "</s:Envelope>"
Response.Write(strSoapReq)
httpRequest.Send(strSoapReq)
Dim strResult
strResult = httpRequest.responseText
If IsNull(strResult) Then
strResult = "No result"
End If
Response.Write("Result from web service: " & strResult);
If I comment out the Response.Write there is no error. The console application completes. If I attempt to write the result, I get a 500 error.
I cannot debug the asp. It is on a production server and there are no Visual Studio IDEs on the server.
Is my SOAP request correct? (strSoapReq)
I am not sure that I am defining the namespace correctly. Should it just be the path with the namespace at the end?
If anyone has any ideas on how to debug this file, I would appreciate it.
Lastly, all the TestMethod() does is return a string, "Connected to TestMethod"
UPDATE
I can connect to my web service. When I run my console application, it returns the standard message of a web service when you but the URL in the web browser. Basically..."
The TestMethod() is not called in the .asp file
When requesting the SOAPAction, is this line correct?
URL = "http://<serverName>:<port>/Service1/Service1.Paging.svc"
httpRequest.setRequestHeader "SOAPAction", URL & "/TestMethod"
Secondly, I suspect my SOAP request string might not be correct.
In defining the namespace, I am doing the following:
'":/Service1"">"'

How to add security (username, password) to grails cxf web service

I created two grails project, one for server side cxf web service and other for cxf client for calling web service..
Everything works fine.
I can call web service from client code and get result.
Now I want to add security, then what will be the changes to server and client grails code?
I tried applying security as said by Christian Oestreich in his post.
http://www.christianoestreich.com/2012/04/grails-cxf-interceptor-injection/
(Grails Cxf Interceptor Injection 2.4.x-2.5.x)
and client code for applying security is as follows
ExampleService exampleService = new ExampleService()
def port = exampleService.exampleServicePort
Map ctx = ((BindingProvider)port).getRequestContext();
ctx.put("ws-security.username", "pankaj");
ctx.put("ws-security.password", "pankaj");
println ".......... " + port.sayHello("pankaj")
But I am getting error as follows
Error |
2014-11-06 18:33:15,411 [http-bio-8088-exec-4] ERROR errors.GrailsExceptionResolver - SoapFault occurred when processing request: [GET] /WSDLDemoClient/wsdldemo/index
An error was discovered processing the <wsse:Security> header.. Stacktrace follows:
Message: An error was discovered processing the <wsse:Security> header.
Line | Method
->> 75 | unmarshalFault in org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor
Instead of above mentioned client code, use following code to get it working.
Map<String, Object> req_ctx = ((BindingProvider)hello).getRequestContext();
req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, WS_URL);
Map<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put("Username", Collections.singletonList("pankaj"));
headers.put("Password", Collections.singletonList("pankaj"));
req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, headers);

REST services - testing PUT methods in the browser

I've developed REST services. I can test the GET methods by the browser, or by a Client Application. But those who have PUT methods I don't know how to consume them by the browser...
For example, I have this method that turns a lamp on, after I insert the userId:
#PUT
#Path("/lampon")
#Produces({"application/json", "text/plain"})
#Consumes("multipart/form-data")
public boolean turnOnLamp(#FormParam("userId") String userId) throws Exception
{
boolean response = new LampManager().turnOnLamp(userId);
return response;
}
In my client application I do this, and it works:
String webPage = "http://localhost:8080/BliveServices/webresources/services.actuators/lampon";
URL urlToRequest = new URL(webPage);
//Authentication
urlConnection = (HttpURLConnection) urlToRequest.openConnection();
urlConnection.setReadTimeout(10000);
urlConnection.setConnectTimeout(15000);
urlConnection.setRequestMethod("PUT");
urlConnection.setRequestProperty("Authorization", basicAuth);
urlConnection.setRequestProperty("Content-type", "multipart/form-data");
urlConnection.setRequestProperty("Accept", "application/json");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("userId", "2"));
(...)
But how can I send the userId by the browser?
Another thing, I get this message when I build my project:
SEVERE: Resource methods utilizing #FormParam and consuming "multipart/form-data" are no longer supported. See #FormDataParam.
Thanks
If you want to test the REST-Webservice with your Browser you must install an plugin.
If you use Google Chrome you can install REST Console I also use these plugin to test my Webservice.
https://chrome.google.com/webstore/detail/rest-console/cokgbflfommojglbmbpenpphppikmonn
For Firefox install these REST-Client
https://addons.mozilla.org/en-us/firefox/addon/restclient/
REST CLient is also available for Safari
http://restclient.net/
For Opera you can check out the Simple REST-Client
https://addons.opera.com/en/extensions/details/simple-rest-client/
For your second Question
please try as Consumes value 'application/x-www-form-urlencoded'
To issue a put-request from a browser you could use jQuery's jQuery.ajax(). (http://api.jquery.com/jQuery.ajax/)
For example:
$.ajax({
url: "test-url",
type: "PUT",
data: {userid: 1}
})
Would send a put-request to test-url with the specified data.

WSO2 ESB Proxy stop replacing %26 with &

I need to send these parameters to domain
domain/page?param1=xxx&param2=yyy%26zzz
I am using proxy in wso2 for domain
localhost:8280/services/proxyfordomain/page?param1=xxx&param2=yyy%26zzz
Endpoint of proxyfordomain is domain
Proxy is replacing %26 with &
Actual URL to be logged in console is:
To domain/page?param1=xxx&param2=yyy%26zzz
But URL logged in console is :
To domain/page?param1=xxx&param2=yyy&zzz
Here param2 will take yyy%26zzz format values
but not yyy&zzz
How to stop WSO2 from replacing?
Thanks for spending your valuable time
You can use the following script mediator configuration to replace 'yyy&zzz' with 'yyy%26zzz'.
<script language="js">var url = mc.getTo().toString();
var newURL = url.replace("yyy&zzz","yyy%26zzz");
mc.setTo(newURL);</script>

Creating client for web service

I have deployed a simple hello service in jboss server. I can view the wsdl file. Can someone help me with the client side. I mean how to access this service? Is there any way to access from web browser? Method deployed is
#WebMethod
public String greet( #WebParam(name = "name")
String name )
{
return "Hello" + name;
}
Try to know what is the wsdl url to access the service which you have just exposed. It might most probably be something like "http://localhost: < port-number >/ems-ejb/?wsdl"
If you type the same in the browser, you should be able to see the wsdl file (page with full of xml tags).
Once done, follow the steps provided here
Example on how to call the method once client stub is generated
String endpoint = "your wsdl url";
GreetImplServiceLocator objGreetImplServiceLocator = new GreetImplServiceLocator();
java.net.URL url = new java.net.URL(endpoint);
GreetIntf objGreetIntf = objGreetImplServiceLocator.getFaultImplPort(url);
String greetings=objFaultIntf.greet("stackoverflow");