问题
Using Visual Studio 2010, I'm calling SOAP webservices and keep getting the error "Error in deserializing body of reply message".
I call the WS method like this:
wsConfig.config_pttClient client = new wsConfig.config_pttClient();
wsConfig.getConfigInput gci = new wsConfig.getConfigInput();
wsConfig.getConfigOutput gco = new wsConfig.getConfigOutput();
gco = client.getConfig(gci); // the exception is thrown here
The method doesn't need input data: I test it using SoapUI and it works fine. Using fiddler, I see the call is made and the answer with all the data correct.
After researching for a while, I tried to alter the readerQuotas
like maxStringContentLength
, maxDepth
etc. inside the xsd
but no luck.
I got a little workaround for the getConfig
method though: when I alter the Reference.cs
file and change the System.DateTime
variable types to string
, it works fine but then I need to invoke a setConfig
method, and that alteration brings another problem... Also, I've read that altering the webservice contract isn't a good practice.
I've been looking for a solution for a while now and here are some places I checked: this, this, this or this.
Can someone help? Thanks
回答1:
Seems I found a workaround for the problem:
in my reference.cs
file under the service reference, I changed every DateTime
and System.Nullable<System.DateTime>
object to string
ones - as I had tried before - being this way able to make the get
method.
When trying to call the set
method, I pass the dates with this:
vt.beginDate = DateTime.Now.ToString("o");
The ToString("o")
seems to be the working solution in order to prevent serialization issues.
来源:https://stackoverflow.com/questions/23990699/webservices-error-in-deserializing-body-of-reply-message