Tuesday, September 09, 2008

WCF Axis Interop Null Problem

I had a small project where I used a WCF web client to connect to an Axis/Coldfusion web service. I could add the service reference and call the web method fine, but the return string (that let me know if the data passed to the web service was processed correctly on the Axis end) always returned null.

I did some logging of the SOAP calls (see previous post) and the service was sending me back the return string, just my automatically generated classes were not reading it for some reason.

So after pooling my hair out for a LONG time, I finally figured out (with the help of a few bloggers) what the issue was.

Well apparently WCF basicHTTPbinding (and possibly other binding types as well) doesn't like rpc style web services. I thought "awww crud" I'm going to have to ask the service company to rewrite their web service, which probably wouldn't go over very well. But then I found this blog.

http://www.vistax64.com/indigo/54127-wcf-client-does-not-read-streamed-response.html

Note in the second post, the poster said he went in and changed the behavior's operational style to use document and literal, and the null problem went away. I did that in my auto generated proxy class (it is hidden by default, you need to click the show all files icon, then it should be named something like References.cs).

I change this-

[System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, Use=System.ServiceModel.OperationFormatUse.Encoded)]

to this -

[System.ServiceModel.XmlSerializerFormatAttribute ( Style = System.ServiceModel.OperationFormatStyle.Document, Use = System.ServiceModel.OperationFormatUse.Literal)]

And wallah! The return string went from null to a value.

Hope this helps someone.

No comments: