WCF:How to Copy value of request into response in WCF - wcf

When i m sending request i am putting some value in that and at the time of response it should contain that value how could we achieve this in WCF ?Could anybody explain with example?Another scenario is if my client sending request to service that service may call another service and so on so at the time of response how to copy that request information inside response?

If you are using DataContract classes in the request and response, then simply read the value in from the request and add it to the response.

Related

Fetch Request body in webclient when using Mono zip to identify which request fails

I am using webclient to call 3 different external APIs in parallel using Mono zip. Now, if any error occurs in any of the API call, I have handled it through a common exception handler using ExchangeFilterFunction. Now, I want to know which particular request fails(out of 3 external API calls) ? Is there any way I can identify that? I also want to append the 'input request body' with the exception response I got from the API call. Can I fetch the request body for which the API Fails (in filter itself)?
In the ExchangeFilterFunction you have access to the request. You could "decorate" your request with some identifier and then use it to resolve the client.
You could add some request header to identify the client.
To keep it internal, you could use request attributes of the WebClient and then read it from the request object
webClient.get()
.uri("...")
.attributes((attributes) -> attributes.put("internal_client_id", clientId))

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.

Mule ESB Flow to pass parameters in Calling SOAP Webservice

I have created on flow in MuleESB which is calling a web-service without any parameter just sending it username, password and token in a property and it is working fine.
But the second API I want to post some parameters while calling soap request but I don't know how to use it I tried to pass through set payload but no response.
use Webservice consumer and add a transform message component beofre it. by doing so you can automatically map all the parameters which are required by the SOAP webservice, as datasence will automaticall download the meta deta of the service using the WSDL file.
Make sure you select application/xml as content type in Postman or SOAP UI and select POST.
Use CXF and select Operation as Proxy Service ,Provide details. Selct and provode (WSDL,MTOM enabled,SOAP Headers ,SOAP 1.2)
Make sure you posting XML request "POST" method in allowed methods.
Use 2 transformers. XML to DOM and DOM to XML.
Log the request using
#[message.payloadAs(java.lang.String)]
Use a groovy script transformer to retreive the entire payload.
def userSoapRequest = new XmlSlurper().parseText(payload);
def userId = userSoapRequest.userId.text();
message.setInvocationProperty('userId', userId);
6.Retrieve userId like above and similarly for all the elements.
7.Process them as you want.
Hope this helps

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

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

Receive a http post in BizTalk orchestration

I have a wcf restful service that accepts http posts.
I am trying to send this to an orchestration with a rcv message set as XmlDocument. (Since no subscribers where found when set to system.string)
The message is received in the orchestration but the xmldocument is invalid so its not possible to do anything with the data(Im sending a string in the http post). (When I attempt it I get an error that the data at the root level is invalid).
How can I get the http post string into my orchestration? Do I need to add a custom pipelinecomponent that adds xml tags to the string to make it a valid XmlDocument?
My solution:
Created a flat file schema where the string in the http post is added to one line. Added a pipeline with a flat file dissasembler with the schema. Use xpath in orchestration to retrieve the string.