i:nil="true" WCF REST request - wcf

I am using a data contract in WCF, but there is some unwanted response tags being sent in the xml file, I am not sure how to modify the data contract class so that I can avoid sending that unwanted response field. In the below XML file, all the text which is bolded and italics is unwanted. Thanks.
I have small problem in xml request and data is coming in the following format
<resller i:nil="true">
What is the reason for this...

Related

The request does not contain a \"file\" part or \"metadata\" part

I have gone through number of forums including the current forum as well, but I couldn't find concrete answer.
Problem Description: Mule sub flow expects JSON (Content-Type=application/json) as input. An attachment with input JSON, should be sent across with http request to third party REST Service.
Following is the source code used.
Sourcecode of Mule subflow
But the third party REST service is responding with Bad request with error message as "code": 400,. "error": "The request does not contain a \"file\" part or \"metadata\" part. However when tried with Postman, the request was successful as shown below
Request successful in Postman
what is wrong with the code?
First, do not specify the Content-Type since the multipart format requires a special boundary section. The proper header will be generated for you once an attachment is present in the Mule Message. If you hard code it, you will have problems.
Second, if the attachment is suppose to be a JSON, then put application/json as the attachment contentType instead of application/octet-stream.
Third, if the problems persists I would suggest enabling HTTP wire logging (<AsyncLogger name="org.mule.module.http.internal.HttpMessageLogger" level="DEBUG"/>) to actually compare the Postman and Mule requests.

Karate support for validating pipe separated response and avro format

We have webservice where we send the request body as binary (avro format) through postman and have a pipe separated response. We were able send this request using karate and get a valid response but made observation that by default karate sets the content type as ‘application/octect-stream’ where as we expect content type to be application/json. Is there a reason why karate uses application/octect-stream for avro format?
Also for pipe separated response does karate support any default validations similar to json/xml validations?
For e.g : if the sample response is like
|PDT|! PRODUCT!|Item1|!SKUID!|sku123a|!DETAILS!|Itemname|itemnumber|price|!FINISH!|
Karate tries to guess the content-type but clearly needs help here, please refer to the documentation for the header keyword, and you can set (over-ride) it easily: https://github.com/intuit/karate#header
For the second question, I suggest you write a simple utility to convert that response to JSON and then you will be able to do all kinds of awesome validations in Karate. This example should be self-explanatory: dogs.feature

how to parse incoming XML file in HTTP request and generate s response based on incoming XML data in Tibco BW

I am new to TIBCO BW development. I need your expert opinion, as I am stuck to create a response XML file. Here is the scenario.
I get a XML file in the HTTP request and after parsing the incoming request XML structure, I have to create a response document which will act as a stub to the incoming request.
First I create a HTTP Receiver which will act as receiving the XML file in the HTTP request. Then I used Parse XML to parse the incoming XML document is correct or wrong. After this activity I am stuck, since I create the Render XML activity after this but it does not fetch the data even after I map the incoming request parsed by Parse XML activity, I can see during Testing time that it is getting the whole XML in the Input but even after mapping the output with input from Parsing, I get NULL values, hence facing errors.
Please let me know where I am doing wrong, or should I use any other method to catch the incoming values, such that I can create a proper response XML document to be used as Response.
Once you received the HTTP request, parsed the HTTP Post Data using the "Parse XML" activity, I really advice you to use a "Mapper" to map your input (received and parsed as an XML) to a XML output schema. This output can easily be returned after.
For example,
My HTTP client send me an XML like this
And I want to return an XML like this with the addition of a and b
The process :
And the mapper
And the end, you can send the XML HTTP response like this :
EDIT (comment) :
To edit the prefix namespaces in a process. You must click on the process (left hand menu) and on the bottom side, there is a button "Namespace Registry"
if you click on it you'll be able to change the prefix name.
But bear in mind, this kind of manipulation can break the existing mapping in the process because everything is XML based in Tibco BW.

Escape characters appearing in incoming message in Mule

My mule application polls XML file from an external endpoint, processes the XML file using XPath expressions, and forwards the payload to appropriate flows for processing.
I am testing the flows by providing the below XML file as inbound message using SoapUI or Mozilla post:
<Employee><Applicant empid="1" firstname="simon" surname="O'Brien"/></Employee>
I am receiving the XML file inside mule flow as below which is perfect and the way I want:
<Employee><Applicant empid="1" firstname="simon" surname="O'Brien"/></Employee>
But when I poll the same XML file from external endpoint, escape characters are still appearing in incoming message:
eg. eg. <Employee><Applicant empid="1" firstname="simon" surname="O'Brien"/></Employee>
I want to receive message with apostrophe (') in place of (').
Can you please advise where I am wrong? Why it is behaving differently for external endpoint and SoapUI?

WCF server returning XML documents with ?xml-stylesheet set

I am creating a REST web service that returns XML documents by serializing .NET objects using the DataContractSerializer. It works very nicely returning documents like:
<?xml version="1.0" encoding="utf8" ?>
<patient xmlns="http://stackoverflow.com/example">
.....
</patient>
by using code like this:
Message MyRestMethod()
{
Patient patientObject = new Patient() {Name="Mickey Mouse"};
Message message = WebOperationContext.Current.CreateXmlResponse<Patient>(patientObject);
return message;
}
However sometimes, the web service is used by a web browser, and so it would be much nicer if it would return documents like this:
<?xml version="1.0" encoding="utf8" ?>
<?xml-stylesheet type="text/xsl" href="/stylesheet/format.xsl" ?>
<patient xmlns="http://stackoverflow.com/example">
.....
</patient>
I have done some substantial digging around, and can almost do it by deriving my own message and overiding OnWriteBodyContents() to get access to the XmlDictionaryWriter. At this point, I then discovered that WriteProcessingInstruction(name, text) not able to write xml-stylesheet instructions.
More importantly, WCF client code receiving an xml-stylesheet processing instruction also bombs out, so even if you "hack" the stream at the character level to add it, it would need not to be sent to WCF clients...
If anyone has a better suggestion, please let me know...
Having dome some substantial reading on this, the answer is that it is not sensible to add an xml-stylesheet marker in the XML being returned to the WCF client.
The markers are processing instructions, which instruct the interpreter to process the XML document in a certain way. In this particular case by applying an XSLT to the document. the WCF serialisation and deserialiser both reject XML with stylesheet processing instructions, which makes sense - as in the WCF client case you do not want the processing instruction to be followed.
However, for my usecase, having the stylesheet processing instruction in when the xml is returned to a browser does make sense, so I have solved my problem by doing a conditional serialisation based on the UserAgent in the request, and in the case of it not being the WCF client application, I am adding the stylesheet to the stream thats used to create the response message.
In such case you are most probably going to to custom message encoder because xml declaration is added by message encoder and it doesn't provide any features to add any other directives.