Failed to serialize the message part
I finally got my hands dirty with some “proper” work after spending ages in the world of Powerpoint, Visio and Word. We are starting up a new project in a few days and i wanted to do some advance R&D on the vendors schemas to see if we would come to any grief with WSDL formats as has happened in the past (e.g WSDLs with Import directives for the XSD’s and also indicating relative paths for those XSD’s).
I picked up a sample WSDL from the set they provided and since i was working from home and couldnt connect to the server at the client site, i decided to create a mock web service and some consumers.
I created the mock web service using thinktecture’s WebServicesContractFirst (WSCF) which we have been using for a long time. All i did inside the service was to create a new response object fill it with some dummy data and send it back. One of my colleagues actually a wrote a more generic WS mocking tool and i’ll post about that sometime soon. I then wrote a regular .NET consumer and a simple orchestration to pickup the WS request message from a file, send it to the mock WS, get & dump the response. Nothing fancy and no mapping needed.
Now comes the interesting part. When i created a sample message for the .NET consumer to send, i left out many elements which, incidentally, were specified as mandatory. I did not tick the option in WSCF to validate the messages (as i have had problems in the .NET 1.1 version with the SoapExtension they generated). The call worked fine and i was able to dump out my request and response messages. Then i decided to submit the same message to Biztalk. Immediately the system threw an error
” Failed to serialize the message part <RequestMessage> into the type <RequestMessageType> using namespace <Namespace>. Please ensure that the message part stream is created properly. “
I found this article on Saravana Kumars blog where he got the same error while calling a webservice in a messaging only scenario. He advises checking that serialization works for all target types. Although the scenario here is different i decided to check if the same error appears if all elements are filled out, mandatory or otherwise. Now once i filled all the elements, the processing worked!!.
A little more digging around and i found this post from Bryan Corazza where he had exactly the same error and this was because an xsd:date element was missing in his request message. I then removed the date element from my working request message and this error popped up again. I put the date back in, took out some other mandatory elements and the error disappeared.
So, it really was the xsd:date after all that couldnt be left blank.
In terms of the serialization, maybe the option to validate the message would have thrown an error. Alternatively, my usual approach is to create a sample file, de-serialize that into the request message object and then call the web service. I decided to skip that and just instantiated the request message and put in some values. Perhaps the de-serialization would have found the error. I need to verify this. I certainly hope it does. But even if it doesnt, the safest thing to do is validate your request message against the XSD first before sending it across. A bit of a no-brainer really but it can save a lot of frustration. Watch out for xsd:date elements!!!