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
Related
I am working on an application with both a front-end and a back-end. The front uses Angular, and the back Node.js (Express). They communicate with a Rest API.
When I request this endpoint with Postman ou directly with my web browser, it works and I get the right result.
However, when I am requesting it since one component of my app, it just doesn't work.
The call is here
console.log("Call GETSAVE");
this.rest.getSave(type, file).subscribe((data) => {
console.log(data);
});
Then, in my service
getSave(type: enumType, path: string) {
console.log(this.url + 'saves/' + type + path);
return this.http.get(this.url + 'saves/' + type + path);
}
with HTTP being an instance of HttpClient (injected in the constructor).
All endpoints of this service work and I call them in the same way as above, but for this endpoint, the subscribe just doesn't work. I never enter the subscribe.
I finally found the answer, and it's quite simple.
By default, HTTPClient will parse data as a JSON. In my case, it was not a JSON but a text.
In consequence, there was an error because it couldn't parse the text as a JSON.
To fix this issue, you need to add a parameter in the request with a "responseType".
In my case :
getSave(type: enumType, path: string) {
console.log(this.url + 'saves/' + type + path);
return this.http.get(this.url + 'saves/' + type + path, {
'responseType':'text'
});
}
I have to send array of ids in GET request as paramenter.How can I test it in Postman(google chrome extension for API testing)?
The scenario is I have url, www.something.com/activity/poi_ids
poi_ids should conatain arrays of ids like [316,318]
At api side using express,
app.get('/activity/:poi_ids',function(req,res){
var poi_ids = req.params.poi_ids;
.......
.......
});
I have looked into it but it is only for post request
you can send them via query params ..
in your http query params assign all values to same variables like
GET activity?pid=12&pid=23&pid=34
and then inside your express get it like
var ids=req.query.pid; //[12,23,34]
It is unstructured text. If you want to "send an array" then you'll need to design some way to encode it and then write JavaScript to decode it.
For example:
GET /activity/316-318
and
var poi_ids = req.params.poi_ids.split("-");
I created web service object from wsdl file and call it like in below. I also print result. this code does not work. web server returns error. because, request has not namespace.
soap.createClient(__dirname + '/wsdl/getCustomerDetails.wsdl', function(err, client) {
.
.
var params= {"custId":"123"};
client.getCustomerDetails.getCustomerDetailsPort.getCustomerDetails(params,function(err,result){
console.log("lastRequest:"+client.lastRequest);
if (err != null)
console.log("error:"+JSON.stringfy(error));
});
}
here what I see in the last request
<soap:... xmlns:tns="http://example.com/api/getCustomerDetails/V01" >
....
<soap:Body>
<getCustomerDetailsRequest>
<custId>123</custId>
</getCustomerDetailsRequest>
</soap:Body>...
but it has to be
<soap:... xmlns:tns="http://example.com/api/getCustomerDetails/V01" >
....
<soap:Body>
<tns:getCustomerDetailsRequest>
<tns:custId>123</tns:custId>
</tns:getCustomerDetailsRequest>
</soap:Body>...
as you see, soap module does not add tns namespace to the request. I tried var params= {"tns:custId":"123"};, it adds namespace to the parameter, but still it does not add namespace to the request, getCustomerDetailsRequest. because of that, I get Unexpected element getCustomerDetailsRequest found. Expected {http://example.com/api/getCustomerDetails/V01}getCustomerDetailsRequest.
how can I force to add this namespace to the method itself ?
I found how I can do that. I think it does not work in default because of a bug in "soap" module. In default, it does not add namespace to the request body. "soap" uses "tns" in default as namespace. there is an option in wsdlOptions. it is overrideRootElement. If you try to override overrideRootElement with tns, it does not add tns to the request body. You have to use different namespace in overrideRootElement. Here my solution,
I first create my wsdlOptions object.
var wsdlOptions = {
"overrideRootElement": {
"namespace": "myns",
"xmlnsAttributes": [{
"name": "xmlns:myns",
"value": "http://example.com/api/getCustomerDetails/V01"
}]
}
};
and then use it when I create soap client,
soap.createClient(__dirname + '/wsdl/getCustomerDetails.wsdl',wsdlOptions, function(err, client) {
.
.
.
}
);
It makes request body uses myns as namespace of root element. Now, I have to modify parameters' namespace, so I defined parameters as
var params= {"myns:custId":"123"};
now, It creates request as
<soap:... xmlns:tns="http://example.com/api/getCustomerDetails/V01" >
....
<soap:Body>
<myns:getCustomerDetailsRequest xmlns:myns="http://example.com/api/getCustomerDetails/V01">
<myns:custId>123</tns:custId>
</myns:getCustomerDetailsRequest>
</soap:Body>...
and, now webserver accepts it.
keep in mind, even tns is defined in the root, it is not added to the request body automatically. Also, if you try to override it in wsdlOptions by tns again, it still does not work. You have to use different value as namespace, like myns
I dwelt sometime on this problem until I saw that the lib get the namespaces from the parsed WSDL (this.wsdl.xmlnsInEnvelope)
xml = '<?xml version="1.0" encoding="utf-8"?>' +
'<' + envelopeKey + ':Envelope ' +
xmlnsSoap + ' ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
encoding +
this.wsdl.xmlnsInEnvelope + '>' +
Then I saved the WSDL inside my project (loading from there) and inserted the namespace I wanted. That worked for me.
I am currently attempting to use node-soap (https://github.com/milewise/node-soap) to make calls to Authorize.net's SOAP server. However, I cannot seem to get my client code pass the proper parameters. I know that the function is calling the server since I get a server error response.
When I examine the WSDL, I notice that the server call requires ComplexType parameters. Is there a way to create the ComplexTypes that I need or can I just use Javascript objects? Here is my current code:
var soap = require('soap');
var url = 'https://api.authorize.net/soap/v1/Service.asmx?WSDL';
soap.createClient(url, function(err, client) {
var args = {
merchantAuthentication: {
name: '285tUPuS',
transactionKey: '58JKJ4T95uee75wd'
}
};
client.Service.ServiceSoap12.GetTransactionDetails(args,
function(err, result) {
if (err) {
console.log(err);
} else {
console.log(result.GetTransactionDetailsResult[0].messages);
}
});
});
The node-soap module is converting your JavaScript object to XML before sending the transaction to the server. It wraps the request in an xml element as outlined by the wsdl. Here is an example of what might be produced by node-soap when passing the object you provided (important to note the outer element is created by the node-soap module according to the wsdl):
This example is using the wsdl for the CyberSource API
<data:requestMessage xmlns:data="urn:schemas-cybersource-com:transaction-data-1.93" xmlns="urn:schemas-cybersource-com:transaction-data-1.93">
<data:merchantAuthentication>
<data:name>285tUPuS</data:name>
<data:transactionKey>58JKJ4T95uee75wd</data:transactionKey>
</data:merchantAuthentication>
</data:requestMessage>
Also, I don’t know exactly how the Authorize.net api works, but it sounds like you might want to check out using username token authentication if necessary:
client.setSecurity(new soap.WSSecurity('username’, ‘password’));
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
};