Error while deserializing (WCF) - c#

I have a class (syncdetails -> implements ichangedataretriever) both on server and client side and I need to pass a syncdetails (changedataretriever) object from server to client, this is an 'out' object.
When deserializing this object that I received from the server I get the following error:
"Error while deserializing parameter [...] " some type was not expected...and then the error says I should add this to my config. But how does my client know that the object it has received has the same type of local syncdetails class.
Greets Daan

Related

How to return type "Assembly" in WCF?

The Servicecontract & OperationContract looks like below:
[ServiceContract]
public interface IAssemblyResolver
{
[OperationContract]
Assembly LoadAssembly(AssemblyLoadRequest loadRequest);
// TODO: Add your service operations here
}
While returning type Assembly, i get below error in trace log:
There was an error while trying to serialize parameter http://tempuri.org/:LoadAssemblyResult. The InnerException message was 'Type 'System.Reflection.RuntimeAssembly' with data contract name 'RuntimeAssembly:http://schemas.datacontract.org/2004/07/System.Reflection' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer.'. Please see InnerException for more details.
On Client Side I get below error:
Additional information: An error occurred while receiving the HTTP response to http://localhost:8769/AssemblyResolverService.svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.
You need to manually serialize Assembly to string using Assembly.FullName and return it. For deserialize string to Assembly use Assembly.Load method.
Server example:
string LoadAssembly(AssemblyLoadRequest loadRequest)
{
return ....Assembly.FullName;
}
Using on client side:
Assembly.Load(LoadAssembly(....));
If you need to serialize assembly as file (if it is not exists on client side), you can try this:
Server example:
byte[] LoadAssembly(AssemblyLoadRequest loadRequest)
{
return File.ReadAllBytes(....Assembly.Location);
}
Using on client side:
var assembly = Assembly.Load(LoadAssembly(....));
But if you load assembly from byte array, you need to use reflection for work with types from this assembly.

Deserialising XML To DTOs In Service Reference

I want to use captured SOAP responses as test data. I've successfully got the SOAP XML and now want to use it to populate the DTOs in my project service reference. This is where I'm coming unstuck.
When I use Message.CreateMessage in conjunction with either message.GetBody or TypedMessageConverter, I have a problem where the deserialiser is trying to populate the PropertyChanged event handler and throws an exception. Why would it do this and how can I stop it?
Added From Comments
Truncated XML:
<GetServiceDetailsResponse xmlns="http://thing.com/thing/">
<GetServiceDetailsResult xmlns:lt4="http://thing.com/thing/types">
<lt4:generatedAt>2016-10-14T14:10:39.7718069+01:00</lt4:gene‌​ratedAt>
</GetServiceDetailsResult>
</GetServiceDetailsResponse>
Code:
string action = null;
XmlReader bodyReader = XmlReader.Create(new StringReader(Resources.eg_xml));
Message msg = Message.CreateMessage(MessageVersion.Default, action, bodyReader);
var b = msg.GetBody<GetServiceDetailsResponse>();`
Exeption
SetUp : System.TypeInitializationException : The type initializer for
'IntegrationTests.GetServiceDetail.Class1' threw an exception. ---->
System.ServiceModel.Dispatcher.NetDispatcherFaultException : The
formatter threw an exception while trying to deserialize the message:
There was an error while trying to deserialize parameter
http://thing.com/thing/:GetServiceDetailsResult. The InnerException
message was ''EndElement' 'GetServiceDetailsResult' from namespace
'http://thing.com/thing/' is not expected. Expecting element
'PropertyChanged'.'

Using suds for python as a SOAP client and failing to handle NoneType

So i'm using suds-jurko for python3 and I have a value in my request like this:
`Date = None`
Date is not a required field. The issue I'm running into is when it processes the request, I get the error:
WebFault: Server raised fault: 'The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://webservices.soapclient.com/v11:request. The InnerException message was 'There was an error deserializing the object of type WebServices.Posting.Request. The value '' cannot be parsed as the type 'DateTime'.'. Please see InnerException for more details.'
Any clue how I can pass a valid NoneType so that my client won't convert it to an empty string?
If the Date field is optional, you should completely skip it and not try to pass any value at all (even if it's set to NoneType).

Unable to send Object while using Web Service

I am trying to send the object through a method api of web service. As service is binded by BasichttpBinding.
OneClickOrder OneClick = new OneClickOrder();
OneClick.Mobile = Session["Mobile"].ToString();
OneClick.OrderDetailsList = OrderDetailsList.ToArray();
OneClick.OrderId = 10000;
OneClick.PromoSiteId = PromoSiteId;
OneClick.TotalPrice = Convert.ToInt32(lblafterDiscount.Text);
var OrderResponse = service.OneClickOrder(OneClick);
While using service API, I got an SOAP exception
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:order. The InnerException message was 'Error in line 1 position 588. 'EndElement' 'order' from namespace 'http://tempuri.org/' is not expected. Expecting element 'Mobile'.'. Please see InnerException for more details.
I didn't get what could be wrong. Is this a problem of Service Side or client side? And i am currently working at client side.
The Problem is that your DataContract class OneClickOrder is not same on both server and client.
At client it is different from Server. So, Check your OneClickOrder DataContract Class, Is both are same on server and client.

PHP server has C# Soap client error on Object reference not set to an instance of an object

So I have a PHP Soap service that is running nusoap and I am writing custom responses.
The php client works perfectly but C# client keeps returning this:
Object reference not set to an instance of an object.
Any ideas on how to troubleshoot this problem?
I've tried initializing every variable with with test data, but I keep getting the same error.
Thanks for your input.
I am using this method.
http://my.execpc.com/~gopalan/dotnet/webservices/webservice_csharp_client.html
This is the error I receive ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException:
Object reference not set to an instance of an object
at gt.MainClass.Main (System.String[] args) [0x0005a] in //Projects/gt/Main.cs:27
line 27 (gt is the wsdl object)
gt.Transact(trans) which I am passing a transaction object and it should return a transaction response,but it appears to not be parsing the response.
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://CANNOT TELL YOUt", RequestNamespace="CANNOT TELL YOU", ResponseNamespace="CANNOT TELL YOU",
This is the method being called and this is a piece of code from the partial class.
ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped, Use=System.Web.Services.Description.SoapBindingUse.Literal)]
[return: System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public TransactResponse Transact([System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] TransactRequest request) {
object[] results = this.Invoke("Transact", new object[] {
request});
return ((TransactResponse)(results[0]));
}
This error was due to xml formatting of the response.
So in this scenario I was taking a wsdl generated by C# ASP.NET and running that wsdl with nusoap on a php5 apache server. (This was do to a client's request to re implement an existing service so they didn't have to change their code.)
So for example if you have
<SomeResponse xmlns='some url'>
< object>
<element>data</element >
</object>
</SomeResponse >
It needs to be formatted like this for .net to parse the xml correctly.
<SomeResponse xmls='some url'>
<SomeResult xmlns:a='some url' xmlns:i=''>
<a:object>
<a:element></a:element>
</a:object>
</SomeResult>
</SomeResposne>
So it looks like the response data needs to be encapsulated by a Result tag which is the concatenation of the function name with the string "Result". So in the example above the function being called is the "Some" function.
I am not a xml or soap expert and I am not sure exactly why this is. I know it has to do with the xmlns:a='some url' tag.
if anyone could explain it better that would be great.

Categories