The XML request payload that Magento API's call method expects - c#

I wrote a generic XML RPC framework in C#. I am now using it to call the Magento API.
I first called the login method and got a valid session ID. But I am not sure what the way to call the call method is because all examples I have seen so far have been of clients using a SOAP proxy to call it from either Java or PHP.
The syntax of those proxy calls reveals that the method signature must be something like this:
proxy.call ( stringSessionId, stringMethodYouWantToCall,
new object[] { param1, param2, ... } );
where call is the method I am referring to. stringMethodYouWantToCall is some PHP side method that the Magento framework's call method will call.
Thing is, when I do this, I get all sorts of errors. But I would digress if I talked about those.
My question really is: could you please provide me with a sample xml-rpc payload that the call method expects. I will build it from there.
Aside
Currently, a Java app calls the Magento API. I could use Fiddler to see the HTTP traffic / request body it sends to Magento, but I do not know how to configure Tomcat to send its traffic to Fiddler.

I am not sure writing your own XML RPC implementation is a good thing, as I am sure there are fully functional C# libraries out there which will solve the issue for you. But if this is some academic or a hobby project, then by all means you should take a look at this generice XML RPC client https://github.com/zendframework/zf2/blob/master/library/Zend/XmlRpc/Client.php. And for a specific use case take a look at the __call method here for the SOAP client https://github.com/zendframework/zf2/blob/master/library/Zend/Soap/Client.php
Just to be sure if you are going the right direction check how they have implemented the entire SOAP client would be a good reference.
Also please take a look here might help you? Which C# SOAP Client Library is easiest to use?

Related

Read SOAP XML message sent as HTTP message body

I have a 3rd party that is sending SOAP XML messages, as the HTTP message body (using HTTP Post). I need to write a program to accept / process these messages.
I have a specification document which contains 2 WSDL definitions - GetTransaction and CutOff.
I am trying to use Postman to send a test message. Content-Type is set to application/xml and the body is set to raw / XML.
I am using C#, ASP.Net (4.7.2), the code is in a Class Library. I have a Controller (ApiController) with:
[HttpPost]
[ValidationAttributes.RequireHttps]
public HttpResponseMessage Service(XmlDocument reqData)
but reqData is always null. I have tried different types instead of XmlDocument.
Now if probably a good time to say that this is all new to me - I've not created a program to accept SOAP messages before.
Should I be creating a WCF Service Application (rather than a .Net Framework Class Library)?
I've tried adding the WSDL "definitions" but they don't seem to produce anything useful. E.g. there is reference to a "GetTransaction" method, but it has a parameter list of about 150 items!?
I have found quite a lot of stuff via Google but it always seems to be about sending, rather than receiving, SOAP messages.
I appreciate that I have not really included much code to look at, but I feel like I've started from the wrong place. So, any basic guidance, suggestions or links to tutorial sites would be most welcome.

How do I provide dynamic twiml instrucions in an outbound call in C#?

I'm attempting to use CallResource.Update() in C# to provide dynamic twiml instructions to a call in progress. I'd rather use CallResource.Create(), but it only accepts a twiml url.
I've not been able to find any documentation or examples on how to do this, and the only documentation I can find that even hints at this capability is in the API reference for the Call resource Update method here: https://www.twilio.com/docs/voice/api/call#update-a-call-resource
Where it states:
TwiML instructions for the call Twilio will use without fetching Twiml from url. Twiml and url parameters are mutually exclusive
Essentially what I want to accomplish is the appointment reminder tutorial but with outbound voice calls as opposed to sms messages.
I need the call to say "Hello {Name}, This is {Company}. We have you scheduled for a {Typeof} appointment on {date} at {time}, if you need to reschedule, please call {Number}" All of the above data is in our database.
I've tried a mish-mash of syntax trying to hopefully luck into the correct way of doing this, but haven't yet managed to find a solution outside of twimlets.
I'd rather not have to stage a public webserver or setup free hosting to do this even though it wouldn't contain any propretary info or PII, it's beyond the scope of my knowledge and time-frame to develop this solution.
I can do this via SMS all day long with twilio so I'm developing a decent knowledge and appreciation for the API, but we have clients that arent sms friendly and require voice calls so I need a solution for them.
var from = new PhoneNumber("Insert Valid Twilio nyumber");
var call = CallResource.Create(to,from, url:new uri("http://demo.twilio.com/docs/voice.xml"));
CallResource.update(
method: twilio.http.httpmethod.post,
url: new uri("http://twimlets.com/message?Message%5B0%5D=Testing&")
pathSid: call.Sid);
In testing this, I'm expecting the message to play the demo, and then switch to say the word testing (which I would later like to implement dynamic twiml instead of using twimlets).
What is actually happening though is that I get an exception stating that the call is not in progress when it gets to the call update statement.
So two problems, one, how do I update the call to the new twiml url, and then how do I substitute the url for twiml instructions like the API documentation states that I can.
Any help would be greatly appreciated.
Twilio developer evangelist here.
That's the first time I've seen the twiml parameter for any REST API resource and given that is the only mention of it, my guess is that we are working on this and have let something slip into the documentation by mistake. For that reason, I would not try to use the twiml parameter right now.
For the error that you're getting when you try to create then update a call:
When you create a call there are more steps than the phone starting to ring. After the call resource is created it is in the "Queued" state. Shortly after, Twilio dispatches the call putting into the "Initiated" state, then when the destination starts to ring it goes into the "Ringing" state. You can check the call lifecycle here. Since your code to update the call runs directly after you receive the response the call is likely in the "Queued" state, thus the error.
If you just need the call to read out a message, then I see no problem with using the Message Twimlet as the initial call URL.
If you need something more dynamic without you having to deal with your own hosting, can I recommend taking a look at Twilio Functions.

Proprietary bare-bone ASP web service

I want to create a proprietary minimal / bare-bone / data-light webservice. I prefer not to use the standard solutions like Restful, WebAPI, SOAP, WCF, etc.
I just want a web server listener that can receive and process 1 UTF8 string (own message format) and respond with 1 UTF8 string as the result.
My question is: can you give me a starting point, by providing a code example of the interface. Of course not the complete implementation.
Data transfer has to be as minimal as possible (no avoidable headers).
NB: Server language has to be .NET. Code example may be in C# or VB.
The most bare-bone thing to create a web service would be an HTTP Handler.
The sample I linked returns HTML but you could send back XML as well (or anything else really, just make sure to return an appropriate Content Type).
The call to your method would be a regular HTTP call of the URL of your Handler.

Making restful calls to asp.net web api

I am currently following this tutorial to create a simple REST service using Web Api. Note this is my first time doing something like this and I am just trying to learn more.
http://www.asp.net/web-api/overview/creating-web-apis/creating-a-web-api-that-supports-crud-operations
I have followed all the instructions and have it successfully running on my localhost. I understand that in this tutorial the URI for all my GET requests look something like:
localhostapi/products/id
And I understand that, and how to perform simple GET requests in the URI and see it actually occuring using my developer tools in my browser.
Now my question is... How do I make POST/DELETE/PUT requests and actually see what they are doing? The guide wasn't too clear, do I pass in parameters into the URI? Does the URI change when I want anything but a GET request? This text here seems to explain it but I do not understand:
The method takes a parameter of type Product. In Web API, parameters with complex types are deserialized from the request body. Therefore, we expect the client to send a serialized representation of a product object, in either XML or JSON format.
It's quite easy to make POST, PUT, DELETE requests. You just need to install Fiddler at http://www.telerik.com/download/fiddler
Next, install and run it. Go to the Composer tab on the right hand side. Next, put your local host URL, and the request method, and other data like the screenshot below
You can write unit tests, like
[TestMethod]
public void GetAllProducts_ShouldReturnAllProducts()
{
var testProducts = GetTestProducts();
var controller = new SimpleProductController(testProducts);
var result = controller.GetAllProducts() as List<Product>;
Assert.AreEqual(testProducts.Count, result.Count);
}
This link also This one may help.
more:
How to call ASP .NET MVC WebAPI 2 method properly
Sending C# object to webapi controller
You can set a breakpoint on your controller methods that handle the post/delete/put.
Same thing in your browser at the point where you call the post/delete/put (presumably in a jquery request)
You can also unit test your controller methods:
http://www.asp.net/mvc/tutorials/older-versions/unit-testing/creating-unit-tests-for-asp-net-mvc-applications-cs

See the SOAP request from Proxy class method calls

I'm using .NET 2.0 web services. If I add a reference to a WSDL and make a proxy class method call, what's the easiest way in VS to see the SOAP being sent?
Example, I added the PayPal WSDL Web Service Reference and made a call as so:
PayPalAPIAASoapBinding _client = new PayPalAPIAASoapBinding();
...rest of code and then
SetExpressCheckoutResponseType checkoutResponse = new SetExpressCheckoutResponseType();
checkoutResponse = _client.SetExpressCheckout(request); // makes the call here
I tried setting a debug point on line 2 but not sure how to dive in to see the SOAP. Obviously I could use something like Fiddler but want to just use Intellisense during debugging to drill down to the object that has the request. I would assume client would have it, my instance above but could not find it. Client is an instance of the PayPal Service.
I do see when I drill down into the base class PayPalAPIAASoapBinding that there is a version property but I can't get the value for this:
System.Web.Services.Protocols.SoapProtocolVersion.Default
when I try to paste that into my watch window, the value just shows the word Default not the true value that's sent. So this is why I need to look at the SOAP and so far in that binding object I don't see a property holding it. But it's gotta be somewhere in any requests you make in a web service in .NET, just don't know where to look during debug?
My end goal here is to be able to read the SOAP envelop before it's being sent really using any WSDL reference in VS.
There's no very easy way. See the example in the SoapExtension documentation on MSDN for a way to log the information.
If you were using WCF, you could just turn on logging in the configuration.
The easiest way to see the SOAP messages (regardless of the programming language) is to use a tool like SoapUI or TCPmon which lets you intercept send and received messages.
This is very easy (if the SOAP is not encrypted). Although it is not in VS.
The easiest way is to use the Fiddler. You can let your VS make Soap calls and see the traffic in raw view on the Fiddler. If the Soap calls are made over SSL, there are some extra steps that needs to be taken for Fiddler to trace them.

Categories

Resources