Handle JSON calls in WCF to single URL with method name contained in request body - wcf

We are replicating an existing service and need to offer the exact same contract.
Requests are posted to a single URL with the method name contained in the request body.
For example the request body of a call to LoginService.Login:
All calls will be made to: http://example.com/json
{"id": "","method":"LoginService.Login","params":{"aUserID":"flip","aPassword":"1234-613E-1240-C55D-9853F37A41B2"}}
How can we accomplish this within WCF? The response should also be JSON.

I didn't know what I wanted was called jsonrpc. Luckily somebody already tackled this problem:
Implement JSON-RPC in WCF

Related

Identify Operation on the basis of xml content posted in WCF Service without including operation name in Url

How to identify operation from xml content posted to WCF Service Url?
Suppose WCF Service Url is http://single.mat.nn.com and client dont want to include operation name in Url.
Problem is to identify operation on the basis of xml content posted .
I am not able to find any solution for this problem. Is it feasible to do configuration in WCF Service that can identify operation method on the basis of xml content posted to WCF Service URL.
One of the scenarios possible in Extending Dispatchers is:
Custom Operation Dispatching. Users can implement dispatching on something other than action – for example, on the body element, or on a custom message property. This can be done using the IDispatchOperationSelector interface.
Implmenting IDispatchOperationSelector will give you access to the incoming message to parse and decide which method you want to forward the request to.
The SOAP web service based on the corresponding method of the SOAPAction field request in the HTTP request. See the screenshot below.
The SOAPAction field and the method section in the request body can view the operation name of the specific request. If you want to recognize this value, we can intercept the SOAP message through the following two interfaces and get the value of the field.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/extending/how-to-inspect-or-modify-messages-on-the-client
https://learn.microsoft.com/en-us/dotnet/api/system.servicemodel.dispatcher.idispatchmessageinspector?view=netframework-4.8
these two interfaces could capture the SOAP message during the communication. We could retrieve the field value and modify it.
Feel free to let me know if there is anything I can help with.

Communication between Podio and WebService using hook

we need to do a communication between Podio and a WebService, and we suppose that the solution is to use hooks.
We have a WebService with one function "createInvoice" with some parameters, and we need to invoke this when we create an item on Podio.
We have read the Podio documentantion but we don't find the manner to do this.
http://podio.github.io/podio-dotnet/webhooks/
As the above link suggests, is it necessary to use a ".ashx" class (Handler) to receive the item from Podio and send the correct information to the WebService or exists another solution?
Thanks!
Its not necessary to be an ashx file.
You just need to have a public URL that expects POST parameters from Podio.
As given in the example code, you need to check the "type" parameter and verify the webhook to enable it.

Yodlee Aggregation REST API error message

I invoked a REST API function and got back the response:
{"errorOccurred":"true","exceptionType":"com.yodlee.core.IllegalArgumentValueException","referenceCode":"XXXXXXXXXXXXX","message":"Multiple exceptions encapsulated within: invoke getWrappedExceptions for details"}
I don’t see anything in the Yodlee documentation describing how to “invoke getWrappedExceptions.”
How do I determine what’s wrong with the REST request I sent that received this response?
IllegalArgumentValueException comes when the parameter for the corresponding REST API is not passed correctly. Please go through the API reference section for the particular API and validate all the parameters you are passing.
If you are using either of the addSiteAccount1 or addItemForContentService1 and getting this exception, then please call either getSiteLoginForm or getLoginFormForContentService and use the correct value form these calls to form the request for addSiteAccount1 or addItemForContentService1.

RESTful API design: inner interaction

Simple question. I read a bunch of articles about API design and didn't find the answer.
How should API's endpoints interact with each other?
For example, if I have 2 endpoints: /category/:name and /messages. What is the best way for example to check category existence from messages?
1) Database query from /messages handler like: SELECT * FROM categories WHERE name = 'test'?
or
2) HTTP request from /messages handler to that endpoint like: httpclient.get('/category/test') ?
or
3) Client should get all categories, get ID of particular category and send request to /messages with that category ID?
The question is simple but not an answer. One thing is sure, never use (2) solution. Requesting some data using http client when you can invoke a method will decrease performance and capacity of your API.
If checking existence of a particular category is required to create response in /messages then use (1) but instead of invoking SQL query invoke the same method as used to handle request to /category/test just invoke it locally not through HTTP.
Solution (3) is the REST-way when each endpoint is responsible only for one type of resources. The disadvantage is that it may require more HTTP requests from client to API.
You should design your application in a way that all the endpoint are calling internal APIs for performing the task. When you want to invoke one operation inside other then you should use the respective internal API instead of any other approach like calling http service.

How to pass object to RESTful Service with GET request?

I have seen some posts in stackoverflow saying "sending list of items in the GET Method, is NOT allowed. It has to be accomplished via POST method only"
My code looks like
[OperationContract]
[WebGet(UriTemplate = "Employee/{emp}",RequestFormat=WebMessageFormat.Json)]
Employee GetEmpDetails(string emp);
and my input json object will be "{'id':1,'name':'test',....}
Is there any alternative way of achieving this issue.
Thanks
It is possible to send list of items with GET, it's just that out of the box only primitive values are supported. String values work just fine, but if you want to pass a complex object, you need to create a custom QueryStringConverter. The post at http://blogs.msdn.com/b/carlosfigueira/archive/2011/08/09/wcf-extensibility-querystringconverter.aspx explains how this can be done.
If you make your service RESTful you will most probably use HTTP PUT for Add method and HTTP POST for Update method. It is absolutely ok to pass object to these methods because objet will be part of HTTP request's body, not part of URI. URI is important for HTTP GET requests. HTTP GET requests should be only for data retrieval not for data modification.
You are mixing up HTTP GET/POST/... requests and REST GET/POST/PUT/DELETE/...
When you wanna request something RESTfully - you do a GET request. In your case I think it should look like
employee/{id}
or
employee/{name}
Please also note that usage of lowercase in the URI is preferable.
If you need multiple GET criteria, I think it could look like:
employee/id/{id}/name/{name}