Fiddler Composer format for HttpGet Request - get

This should be an API 101 question. I'm stuck. I have a working hosted API that accepts an HttpGet request to return a simple "Hello" response. My ASP.Net app works, but I can't seem to test this using Fiddler (and then move to an Android App). The ASP web service declares:
[OperationContract]
[WebInvoke(Method = "GET",
RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "SayHello/{userId}")]
string SayHello(int userId);
I cannot figure out what format to use for the Get request: I've tried:
In Fiddler I compose a localhost test as:
http://localhost:51276/AppWebService.svc?SayHello (returns wdsl page)
http://localhost:51276/AppWebService.svc/SayHello (returns 400 error)
http://localhost:51276/AppWebService.svc?SayHello&userId=1000 (returns wdsl)
So, I'm not sure what I'm 'composing' wrong.

Related

RestSharp POST not returning anything from Azure environment, but does locally

I've made this type of call dozens of times, but for some reason this isn't working in my testing environment in Azure, but works on my localhost just fine. The result never returns from my service, not even a timeout error or "0" response, nothing. What could I be missing when calling an api endpoint? No errors in my logs either.
The only way I'm able to get a response is if I remove the Timeout = 2700000, which in that case it returns "0" response. But my call is taking more than a few minutes, so without the Timeout set, it will always return a "0" response.
UPDATE: I've also tried using await/async calls, no luck either.
UPDATE: I switched from restsharp and used a Httpclient call instead, and still same results. So I don't even think its a restsharp issue alone.
var appSettings = ConfigurationManager.AppSettings;
var restClient = new RestClient(appSettings["Url"]);
var request = new RestRequest("api/Sync")
{
Method = Method.POST,
Timeout = 2700000,
RequestFormat = DataFormat.Json
};
request.AddHeader("authUser", appSettings["username"]);
request.AddHeader("authPass", appSettings["password"]);
request.AddHeader("Content-Type", "application/json");
var body = JsonConvert.SerializeObject(deserializeItem);
request.AddParameter("application/json; charset=utf-8", body, ParameterType.RequestBody);
var result = restClient.Execute(request);
var response = JsonConvert.DeserializeObject<ResultObj>(result.Content);
So in order to fix this issue, I had to put:
System.Net.ServicePointManager.SetTcpKeepAlive(true, 180000, 60000);
The connection between my web job and service was timing out due to idle inactivity.

Consume WCF service using Node.js

I am consuming my WCF service using Node.js. I am using WCF.js package.
I am able to communicate with the service but not able to fetch data.
I am getting the response action method in response.
I have tried WCF.js package.
Following is the code that i tried
var result;
var BasicHttpBinding = require('wcf.js').BasicHttpBinding
, Proxy = require('wcf.js').Proxy
, binding = new BasicHttpBinding()
, proxy = new Proxy(binding, " http://domain:port/myservice.svc")
, message = '<Envelope xmlns=' +
'"http://schemas.xmlsoap.org/soap/envelope/">' +
'<Header />' +
'<Body>' +
'<GetConnections xmlns="http://tempuri.org/"/>' +
'</Body>' +
'</Envelope>'
proxy.send(message, "http://tempuri.org/IMyInterface/GetConnections", function(result, ctx) {
console.log(result)
});
I am getting following response
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<ActivityId CorrelationId="ba0b223b-a823-47ff-826d-467d595f0bc7"
xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">47ff68ec-2083-417f-b29d-52571c4cd153
</ActivityId>
</s:Header>
<s:Body>
<GetConnectionsResponse xmlns="http://tempuri.org/">
<GetConnectionsResult xmlns:a="http://schemas.datacontract.org/2004/07/vRanger.API.Types.Common" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/>
</GetConnectionsResponse>
</s:Body>
</s:Envelope>
I want the data to be returned.
Can anyone help me with this.
I didn’t get your point, this xml response is the returned result. What is the data? If you want to parse XML document, we could use the below JavaScript DOMParser.
Parse XML using JavaScript
https://developer.mozilla.org/en-US/docs/Web/Guide/Parsing_and_serializing_XML
In addition, it seems that the result is empty in the GetConnectinResult node.
<GetConnectionsResult xmlns:a="http://schemas.datacontract.org/2004/07/vRanger.API.Types.Common" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/>
If the GetConnections method has the returned result, there might be some parameters in the method signature. Thereby we need to add the value of the parameter.
"<GetConnections xmlns='http://tempuri.org/'>" +
"<value>123</value>" +
"</GetConnections>" +
At last, I do not see the library's support for complex data types, where the result returned is a custom object.
https://github.com/yaronn/wcf.js
Please try the below link.
How to consume WCF soap web service in node.js

ERROR - TypeError: Type error only on Safari after made GET request to the api server inside angular 5 app

So I am making the web app on top of angular 5.
The problem is when I try to call the api endpoint from the server.
When I get an error response (400+), it seems like on Safari it always throws and breaks the app.
ERROR - TypeError: Type error
ERROR CONTEXT – DebugContext_ {view: Object, nodeIndex: 0, nodeDef: Object, …}
But on Chrome it can handle the error correctly like this.
GET https://api.xxxx.com/projectname/v1.0/validation/access-token 400 (Bad Request)
This is my source code
const baseUrl = environment.apiUrl;
const fullUrl = baseUrl + '/productname/v1.0/validation/access-token';
const headers = new HttpHeaders({
'X-Access-Token': access_token
});
this.http.get(fullUrl, {
headers: headers
}).subscribe((res: any) => {
console.log(res, 'http res');
},
(error: any) => {
console.log(error, 'http err');
});
Anyone has an idea how to fix this?
After a lots of debugging, I figured out the issue that was causing for me. In every request, I was sending the name of the mobile device and for my case it was, Shashank's iPhone.
Calling setRequestHeader with single quote in the header was failing and hence all the HTTP request broke.
I had a Flutter App using an Inapp_Webview that points to an Angular 1.X web application and was also receiving a TypeError for all XHR requests after changing my iOS device name to include an apostrophe.
(*wanted to leave a comment, but didn't have the rep yet)

How to get body content from request in mobile service in Azure

I crate a mobile service and also a custom api for that in Azure. I use fiddler to send request and do some basic and simple testing.
At Azure side, I create a custom api for my mobile service. Let say the name is ExampleCustomApi. And in the code I have
exports.put = function(request, response) {
var tags = request.parameters.tags;
...
...
}
At fiddler side, I set http method to "PUT" and the url to my custom api.
Then I set a request body to { "tags": "tag1" }.
When I execute the request in fiddler, I receive 500 back. The log in Azure's mobile service says that parameters is undefined.
My question, then, is how to get the request body at the server side. I look at the document of request object, it seems to me that parameters is the one I should use, but it doesn't work.
request is an object in express.js library.
This is the documentation from MSDN http://msdn.microsoft.com/library/azure/jj554218.aspx
the documentation from express.js http://expressjs.com/api.html#req.body
And I can use request.body to get the body content.
After many attempts we cracked getting the content from a weburl. Hope this helps :) Jsonbody would hold your page content. This is a copy where we pulled json from one of our API's
var message = "try";
var jsonBody = "";
var request = require('request');
request.get({
url: "https://superduperwebaddress.com/api/pull"},
function(error,response,body){
if(!error)
{
var mybody = JSON.parse(body);
jsonBody = mybody;
console.warn("we are here well");
}else{
console.error(error);
}
}
);

How to return only status code in POST request in servicestack Instead of HTML page

have created REST service using servicestack and in post request I have return object in following way
return new HttpResult(request)
{
StatusCode = HttpStatusCode.Created,
};
request: object which i have posted in database
When i check it in fiddler it render whole HTML Page of servicestack in response body, instead of that i would like to return Status code only, so please tell me how can i do?
Thanks
There was a bug in versions before < v3.05 that did not respect the HttpResult ContentType in some scenarios, it should be fixed now with the latest version of ServiceStack on NuGet or available from:
https://github.com/ServiceStack/ServiceStack/downloads
Prior to this you can still force the desired ContentType by changing the Accept:application/json Request Header on HttpClient or by appending ?format=json on the querystring of your url.
So now if you don't want to have any DTO serialized, you don't add it to the HttpResult:
return new HttpResult() { StatusCode = HttpStatusCode.Created };
Note you still might get an empty Html response back if calling this service in the browser (or any Rest Client that Accepts:text/html). You can force a ContentType that won't output any response if it has empty payload (e.g JSON/JSV) by specifying it in the result as well, e.g;
return new HttpResult() {
StatusCode = HttpStatusCode.Created,
ContentType = ContentType.Json
};

Resources