Friday, May 30, 2014

WCF SAP Adapter XmlReaderParsingException

If you run into this exception:

A message sent to adapter "WCF-Custom" on send port "SENDPORT" with URI "sap://CLIENT=123;LANG=EN;@a/ABC/00?GWSERV=DEF&RfcSdkTrace=True&AbapDebug=False" is suspended.
 Error details: Microsoft.ServiceModel.Channels.Common.XmlReaderParsingException: The length of the value for the field exceeds the allowed value. Value: 4  Field: TDSPRAS Allowed value: 2

then you should check the IDoc-XML carefully. Since the generated XSD itself does not necessarily check for maxLength (it might only define xsd:string), the IDoc-XML might successfully validate against the schema. However, during run-time the WCF SAP adapter checks the field length against the IDoc specification and fails.

You can find the real field length actually in the flat file attribute pos_length.

Also keep in mind that the length value is doubled (at least, in our case). The exception message says that a length of 2 is allowed, but actually only 1 is allowed. I suspect that there is some encoding reason behind.

Solution: You can enrich the generated XSD by using all pos_length values in MaxLength. This way the error will be seen earlier.

BTW, if you transfer IDoc as a flat file and thus use the Flat file-Assembler, you won't run into that problem since the assembler just cuts the overlength. ;-)

No comments: