Axis2 Mapped JSON does not return faults fully in JSON - axis2

The application I work with utilizes Axis2 and I'm having a problem with JSON support and faults we're returning. I've deployed the ADB stock quote service per the quick start guide as a sanity check and followed https://axis.apache.org/axis2/java/core/docs/json_support.html to add mapped JSON support. I forced a server fault to see how it would be returned and, similar to the application I work with, I'm getting a mixture of JSON and XML:
{"Fault": "<soapenv:Fault xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">soapenv:Server</faultcode>Unexpected subelement {http://quickstart.samples/xsd}symbol2</faultstring></soapenv:Fault>"}
I'm hoping to get the fault in full JSON so the faultString can be easily accessible with JSONPath. What am I missing to have server faults returned in such a way?

Related

WCF converting decimal value to zero

I am using SOAPUI to call a WCF endpoint with a decimal value. Somewhere the value is getting converted to a zero.
I can call the same service, with the same parameters from a .NET application and the value is not getting altered. I can de-serialise and inspect the values being passed from my .NET app and SoapUI, and both de-serialised versions of the object are identical.
I have been able to capture the request in Fiddler after it has left SoapUI and the decimal value is still in tact so I know it is getting converted down stream somewhere.
This post suggests that this can happen when the proxy is generated:
int properties are 0 when consuming WCF in .Net 2 - but evidence is not pointing to this being a problem in the service, not the client.
Apologies I can't share WSDL nor XML due to corporate privacy restrictions.
The resolution in my case was to change the order of my request parameters.
I was able to determine this by enabling WCF tracing, including message payloads, and then comparing the payloads from my .NET application against the payloads from SoapUI.
The payloads are massively different, but ignoring namespaces, correlation ids, keys and dates I was able to determine that my problematic parameter was in a different position. Changing the order within SoapUI XML request resolved the issue.

How to build a WCF service that consumes data given an XSD

I have been provided an XSD and a sample Xml file that contains the results I will be getting.
I am to build a Web Service that accepts this data and enter into a SQL 2005 table. Each time my service is invoked, I am expecting 1200+ rows of data.
I have also been provided two Xml files, success.xml and failure.xml, that are responses I am to provide back to the caller?
I would like to build a WCF service on the .Net 4.0 framework with one 'MethodToCall'. The other party would call this web service and pass in the data.
I used the SVCUTIL.exe file.xsd /dconly /importxmltypes to get an output.cs file.
Now what do I do?
How do I iterate through the rows to add to my table?
With so many rows, will I run into issues of having my service timeout or something?
Can I do the table insert/update in a batch after disconnecting from the wire?
Any sample or pseudo code would be appreciated.
How do I iterate through the rows to add to my table?
usually it generates classes using List for sequences in XSD, so you can iterate using foreach.
With so many rows, will I run into issues of having my service timeout
or something?
There are settings of binding like
<readerQuotas
maxDepth=""
maxStringContentLength=""
maxArrayLength=""
maxBytesPerRead=""
maxNameTableCharCount="" />
consider to increase its values.
Can I do the table insert/update in a batch after disconnecting from
the wire?
Think again, do you really need it? You should send response to sender that data is successfully processed. But you are going to send the response before data is written to the database. It could cause problems.
if the xml you got is not a soap envelope than you cannot build a wcf service that gets exactly it. you can build a service that gets that xml wrapped inside soap. that may or may not be what you want. to build a service that gets exaclty this xml use asp.net web api.
to build a wcf service given an xsd (and considering the limitation above) use wscf.blue.

Transfer XML between systems with Biztalk and WCF

I have system A which produces an xml-file and system B which takes the file. How can I implement this exchange using Biztalk with WCF?
You have two possible different solutions as I see it and it basically comes down to how typed you WCF service needs to be.
Do you need to transform you message into a new format? Or are you planning to use other features in BizTalk as content based routing etc? Are you at all interested in the content of the message while in BizTalk are you OK with just passing it thru?
If you are looking for a solution with the capabilities as described above you'll need to get the schema for the XML message you want to receive into WCF service and publish that service. Once the message is in BizTalk it's then typed and you can do what ever with it using BizTalk.
If you however just want to pass it thru you could just publish a service that received as message of type XML document and pass that thru. Here's a good post describing the a few different techniques to create a generic service accepting any XML as input.

Add Service Reference "___ is already defined"a

I have a WCF web service that I am working on and I built it and was delighted to find that I could use complex types in it. I added some and then realized that they were still not useable as those types on the client end. This is an internal web service so these types are known on both sides. Anyway, that's not the problem, as I took the complex types out, but I think it may have left some residual issues.
When I then changed my additions to all be base types (string, date, int, etc) then added the web service to the client project, I got a "[enumtype] is already defined" error. It occurred in the reference.cs file so I opened it up. Sure enough there were duplicate enums. Plus there were a bunch of helper (serializing) functions. The duplicate enum was from code that had been in there before I picked this web service up to work on. It had not caused an issue previously.
I opened up the reference.cs for the previous (successful) service reference. It did not have the duplicates or functions and also I noticed a difference between the entries that were in there. The reference.cs that was failing to compile had this additional attribute in several places:
[System.ServiceModel.XmlSerializerFormatAttribute()]
I also see that my new failed code was using string[] and the old was using ArrayOfString. I did not intentionally change this, but must have somehow set something differently in the process.
Does anyone have a few clues?
Thanks!
Have you tried deleting the service reference from the project and re-adding it? You may have to manually remove some (or all) of the serviceModel contents too. If that is the only Service Reference then definitely remove the serviceModel element contents too.
Once its all gone, re-add the Service Reference. If you're still having problems then it may be that the service metadata is generating invalid WSDL causing the duplicate enums.
UPDATE: Just for verifying the WSDL is not valid, you could try creating the service proxy manually using the SvcUtil command line utility. It generates your proxy code like Visual Studio does and may give you more troubleshooting info.
After a lot of experimentation this is what I found out:
Our web service up to this point was using the Request / Response classes for input and output. There were required in 1.0, and were a carry over from that. I attempted to create a simple entry point that sent in a string and returned a string. This compiled ok, but:
Although you can use regular types for input and output, if you are using Request / Response types exchanges for other entry points, then you cannot.
Mixed method of request / response and regular types will compile, but it will not successfully import (at least into Visual Studio 2008). What ends up being created seems to be an attempt to create input and output classes for all of the functions to translate them to their complex types, along with the Request / Response types which creates duplicate entries and will not compile.
This then also means that you cannot send in a request object and return a string (which is how I found out that this was not allowed) – this generated an error in the unit test, which started me down this path.
So if you have a request / response web service, all functions must follow that protocol.

MsmqIntegrationBinding Serialization with Unknown Message Body Types

I'm looking to use the MsmqIntegrationBinding to integrate with a legacy queue which has a serialized object as the message body. Has anyone come up with a way to obtain the "metadata" of the message body and create a service side class to use within the service?
For example, if I put in a serialized Product object from System A and my service needs to consume it, how do I provide MsmqMessage the type if I do not have the Product class on my side? I was thinking of reading off a message in a separate program, deserializing, and then emitting via the code dom. Ideas?
I wholeheartedly recommend against attempting to emit the deserialized type at runtime in the message destination. Either work with the XML at the destination to obtain the data you desire, or build data contracts that both the source and destination can adhere to.
Hmm... in WCF, you can define service methods which take (and optionally return) an untyped Message type. This seems to fit your bill quite nicely.
Other than with strongly typed messages, you'll have to do all the putting together of the message on the client and the taking apart on the server by means of reading the raw XML - but that seems to be what you're looking for, right?
Find more information and samples here:
WCF - Handling Generic Messages
How to pass a generic object through WCF
Untyped messages on WCF
Untyped messages have some restrictions, e.g. you can only read them once on the server, but you should be able to manage your scenario with this, I think.
Marc