I need to make a call to a webservice and at the moment i am doing it this way:
private var myWebService:WebService = new WebService();
myWebService.loadWSDL('path to wsdl file');
myWebService.addEventListener(ResultEvent.RESULT , function(event:ResultEvent):void {
trace(event);
});
myWebService.addEventListener(FaultEvent.FAULT , function(event:FaultEvent):void {
trace(event);
});
myWebService.soapcallName();
Now i would like to do the same thing but without loading the WSDL file and doing the soapcalls directly to the right url. Is this possible?
Yes, I had to do this when our WS calls had to hit a proxy in a DMZ, but the WSDL for the ACTUAL service was behind a firewall and unreachable. But it is a tricky process.
First you will need to create the soap post requests manually. You can read all about the structure on wikipedia http://en.wikipedia.org/wiki/SOAP . This means you will need to generate all calls manually since you can't say SomeService.SomeMethod without the wsdl loaded. Now the next problem you will face is actually sending it out. Because you need to add custom http headers on a POST, you will need to build the full request document (strings and line breaks etc) and send it over a socket (HTTPService will not support custom headers on a POST). If you need more help getting this going, I can add further examples on here.
Example:
You need to basically create a method to generate SOAP Envelopes. Here's a quick i.e. from the link I gave you...
private function getStockPrice(symbol:String):String{
// you can do this with xml also and call toString() on it later
var envelope:String = "<?xml version=\"1.0\"?>";
envelope += "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">";
envelope += "<soap:Header></soap:Header>";
envelope += "<soap:Body><m:GetStockPrice xmlns:m=\"http://www.example.org/stock\">";
envelope += "<m:StockName>" + symbol + "</m:StockName>";
envelope += "</m:GetStockPrice></soap:Body></soap:Envelope>";
return envelope;
}
Then you call getStockPrice("IBM") which will return the ready to go SOAP envelope that you will use as the POST body of your call. Note that in the example, you will have to know the information that would have been in the WSDL ahead of time like method names, param names etc. Use the Socket() class to send the post body to the server since you will need to add a custom SOAPAction header. If you need help with that part, here is a class to begin hacking on that already does that... use it instead of HTTPService. RestHTTPService.
Related
I have an AspNet/AngularJS website (using System.Web.Http version 5.2.6.0), I'm adding card payment integration, with 3DS security. 3DS has this step called "data device gathering" where the PSP endpoint sends you back an url and you have to post it into a hidden iframe on the frontend.
Presumably there's some javascript that gathers the device data, and then redirects the iframe to an url you have provided. It almost doesn't matter what page is behind that url, the important thing is listening for the redirect. It just needs to contain some specific html so you can verify you were redirected to the correct page.
So I just added a static page to my website and provided the url. The redirect attempt resulted in "405 method not allowed" because the PSP's device gathering logic does a POST to the redirect url.
So I'm trying to make an API method that allows POST and returns a html page. This has proved unexpectedly challenging. These are some of the things I've tried from answers here on StackOverflow:
[HttpPost]
[AllowAnonymous]
[Route("methodnotification")]
public NegotiatedContentResult<string> MethodNotification()
{
return base.Content(System.Net.HttpStatusCode.OK,"<div id = \"threeDSMethodData\" name = \"threeDSMethodData\" > PROCESSING...</ div >");
}
This will return the following in PostMan:
"<div id = "threeDSMethodData" name = "threeDSMethodData" >
PROCESSING...</ div >"
It may look OK, but it's actually a string of type application/json; charset=utf-8. I tried the POST from FireFox, it returns this:
< string> <div id = "threeDSMethodData" name = "threeDSMethodData"
> PROCESSING...</ div > < /string>
Even setting the Accept header to only accept "text/html" will return a "plain text" not html.
I've tried different overloads of base.Content, which required me to add a "formatter" (if I also wanted to specify content type), and change the return type of the method to FormattedContentResult. After experimenting with different formatters I gave up because it just keeps giving me JSON or string.
I've also tried the following:
return new System.Web.Mvc.ContentResult
{
Content = "<div id = \"threeDSMethodData\" name = \"threeDSMethodData\" > PROCESSING...</ div >",
ContentType = "text/html"
};
Note the fully qualified name was necessary here because if I add a using statement for System.Web.Mvc, all my annotations start giving me "ambiguous reference" between System.Web.Mvc and System.Web.Http. This approach also returned a JSON file.
How do I return html from a POST in ASPNET?
EDIT: The API project targets .NET Framework 4.6. I wish I knew which version of ASPNET that corresponded to.
Try to change the function definition from
public NegotiatedContentResult<string> MethodNotification()
to
public ContentResult MethodNotification()
You should use NegotiatedContentResult if you are passing an object to be made text/json i.e:
NegotiatedContentResult<MyDTOClass>
This is why you receive the json string.
By spefifying NegotiatedContentResult<STRING> you break the text/html contentType, cause string implies, json string
If I have the following piece of code
script.
function getProductParams(params) {
return JSON.parse(localStorage.getItem(params));
}
each product in products
-var getVariable = getProductParams("ids");
This piece of code doesn't work, I'm guessing that - is on server side, while script. is on clients?
How can I access a variable from localStorage in pug and use it for comparison with variables received from server.
I want to make something like this
script.
function getProductParams(params) {
return JSON.parse(localStorage.getItem(params));
}
each product in products
-var getVariable = getProductParams("ids");
-if (getVariable.includes(#{product._id}) {
// create the element in html
-} else {
- // call next product and compare if we have it
-}
The simple answer is that you can't do this. LocalStorage is exactly that - local. Your server can't directly access it unless you explicitly pass it back using some other format/method.
What your server can access easily is the cookie. If you store the data in the cookie and use cookie-parser then you can handle this list quickly. This use case is exactly why cookies exist.
Another option would be to pass the data to the server in the body of a POST request, but your question doesn't provide a lot of information as to what exactly you're doing and if this is an option or not.
It would also be much easier for you to accomplish all of the sorting and filtering in your route instead of the pug template. That way you have full request to the cookie, request body, etc. directly and you don't have to pass that down to the template too.
Then, when your template gets the list it's a really simple matter to render it:
each product in products
//create the element in html
I am using SignalR in MVC to display information in a basic chat type device in MVC. This is all working ok but I want to display information from a Json payload that has been deserialized like this:
Dim iss As IssueObjectClass = JsonConvert.DeserializeObject(Of object)(json)
The information does not have to being displayed does not just have to be an object it could be a variable as well, for example I could also display this:
Dim key = iss.issue.key
I have the code for the connection using the chat hub device which is displaying basic information (Message and username). Is this the way that I should try and display my Json using SignalR. I know that SignalR is used for real-time web applications but I am unsure on how it could display information that has been fired from a webhook as a Json payload.
This is how I am displaying the messages in the chat hub, but I want to display information that is coming from a webhook unrelated to anything that has been typed on the application. I want to display information from a HTTP POST from JIRA:
var encodedName = $('<div />').text(name).html();
var encodedMsg = $('<div />').text(message).html();
$('#discussion').append('<li><strong>' + encodedName + '</strong>: ' + encodedMsg + '</li>');
$('#discussion').text = encodedMsg;
How can I integrate SignalR with Json to display it?
It's a pretty simple thing to do, and a common case with SignalR. In your code where to receive and deserialize your object, you just have to call something like:
var context = GlobalHost.ConnectionManager.GetHubContext<YourHub>();
context.Clients.All.broadcastIssue(iss);
On your client you'll have to define a handler this way before you start the connection:
var yourHubProxy = $.connection.yourHub;
yourHubProxy.client.broadcastIssue = function (iss) {
// ...do your stuff...
};
This is very basic code which would need to be better organized, but it should put you on the right track. My advice is you go through the official SignalR documentation, which is extensive and well done, in particular the guides to the APIs.
I am accessing a third party web service using JAX-WS generated client (Java) code.
A call to a service that initiates a client session returns a Token in the response which, a.o., contains a Signature. The Token is required in subsequent calls to other services for authentication purposes.
I learned from using SoapUI that the WS/Endpoint requires the Token to be used as-is... meaning everything works fine when I literally copy the Token (which is one big line) from the initial response to whatever request I like to make next.
Now I am doing the same in my JAX-WS client. I retrieved a Token (I copied it from the response which I captured with Fiddler) and I tested it succesfully in a subsequent call using SoapUI.
However, when performing a subsequent call to a service using the JAX-WS client, the Signature part in the Token is changed. It should look like:
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">...</Signature>
But (when capturing the request with Fiddler) it now looks like:
<Signature:Signature xmlns:Signature="http://www.w3.org/2000/09/xmldsig#" xmlns="http://www.w3.org/2000/09/xmldsig#">...</Signature:Signature>
Apparently this is not acceptable according to the WS/Endpoint so now I'd like to know:
Why is the Token marshalled back this way?
More importantly, how can I prevent my client from doing that?
Thanks in advance!
Have you tested it? It should work nevertheless. The original signature used the defautl namespace (...xmldigsig) the JAXB version uses the same namespace but explicit says that the Signature element belongs to that namespae (Signature:Signature). The effect is the same, both xml express that Signature is in the http://www.w3.org/2000/09/xmldsig# namespace
You can customize the jaxby output with #XMLSchema on the package info, #XMLType on the class or inside the element.
http://blog.bdoughan.com/2010/08/jaxb-namespaces.html
By the help of #Zielu I was able to solve this by altering package-info.java (in the package of the generated files) like so:
#javax.xml.bind.annotation.XmlSchema(
namespace = "http://namespaceofthirdparty-asingeneratedversionof package-info.java"
, xmlns = {
#javax.xml.bind.annotation.XmlNs(namespaceURI = "http://www.w3.org/2000/09/xmldsig#", prefix = "")
}
, elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) package com.where.generated.files.are;
I'm developing a simple youtube app in adobe air, so far I could get the approval window in youtube and getting the token for uploading. However I'm stuck in the part where you send the data on POST with all the information (https://developers.google.com/youtube/2.0/developers_guide_protocol_direct_uploading)
I already loaded my video data as a bytearray, what I need is to create the whole POST request containing all the information as it shows in the link. (the xml atom feed, the bytearray data, etc.) I have all the information needed, I just need to structure the POST request.
How to do that in as3/air? Do I create all the information as URLVariables? which ones are headers and which ones arent? How do you add the --< boundary_string> to the POST? How do you add the bytearra to the POST? All help is highly appreciated.
Thanks!
I have always done something like this when sending POST variables:
<fx:Declarations>
<s:HTTPService id="loginServ" resultFormat="text" result="onResult(event)" method="POST" url="http://www.myurl.com/login.php"/>
</fx:Declarations>
Then you would have two functions, one for sending the request and one for handling the result you get back:
private function login():void{
//Make a new Object to hold all of your POST variables
var reqInfo:Object = new Object();
//Then set the properties of that Object to be each POST variable
reqInfo.username = "admin";
reqInfo.password = "password";
//Finally, send the request with the Object as the parameter
loginServ.send(reqInfo);
}
private function onResult(e:ResultEvent):void {
trace("Result:" + e.result);
}