NetDataContractSerialization throwing deserialization error - wcf

I have methods which return interface and some methods which accepts interface as parameters. I am trying to use Net DataContractSerializer but I am getting following error...
The formatter threw an exception while
trying to deserialize the message:
There was an error while trying to
deserialize parameter
http://tempuri.org/:id. The
InnerException message was 'Error in
line 1 position 120. XML 'Element'
'http://tempuri.org/:id' does not
contain expected attribute
'http://schemas.microsoft.com/2003/10/Serialization/:Type'.
The deserializer has no knowledge of
which type to deserialize. Check that
the type being serialized has the same
contract as the type being
deserialized.'. Please see
InnerException for more details.
Please help me how to resolve this error....
If I use Netdatacontract attribute on Operation Contract, can i use DataContract and Datamember attribute on serializable class???
Thanks in advance...

Just guessing - the error seems to indicate the NetDataContractSerializer can't properly determine what type to deserialize your content into.
Could it be that you're not specifying the http://tempuri.org XML namespace to the deserializer??
Also, can you show the content of the InnerException, please?
Or second option: using the NetDataContractSerializer, you need to also share the data contracts between server and client, so that the client can deserialize to the exact same type as was defined on the server side. Are you missing this requirement, maybe??

Related

Chaining Promises with custom error types with Kovenant

I'm using Retrofit to access a REST API and I would like to use Kovenant's then function to chain several units of work. In other words, I want to feed the output of one API call as a parameter to another API call.
I've defined a custom error type that includes a property to contain API specific error codes defined as follows:
class ApiError(val statusCode: Int, val apiErrorCode: Int, val message: String)
If an error occurs during an API call, an instance of this class is created with the appropriate error codes.
According to Kovenant's documentation, I can create an instance of Deferred<V, E> to obtain a Promise<V, E>. I was hoping that I could supply ApiError for the generic parameter E. I didn't see any generic constraints in Kovenant's definition of Deferred that seem to require E to be an Exception.
That being said, when I attempt to chain two functions that return Promise<V, ApiError> using then, I receive a compiler error stating that the expected type for then is a Promise<V, Exception>.
Can I make Kovenant work with a custom error type and if not, is subclassing Exception to include the properties I need the correct solution for what I'm trying to achieve?
Some of the base definitions do not have generic bounds for E but almost all of the extension functions do indicate the E is of type Exception. Viewing the source code in Kovenant promises-api.kt shows that it is clear that most things have this expectation.
You can simply change your error class to be a descendant of Exception:
class ApiError(val statusCode: Int, val apiErrorCode: Int, message: String) : Exception(message)
Then you can throw it to fail the Promise or use it to call fail on the Deferred.

Passing a default Integer value to a WCF service in Biztalk

I have consumed WCF service in biztalk through "Add generated items". There is a method in WCF which takes an integer parameter. In orchestration I want to pass that method a default value or say I want to hard code input value. How I can achieve this. I have googled this question but didn't get any adequate result.
What I have done is declared an integer variable assign it a value, then I assigned that variable to a message of Integer type.
Now how I can assign this message to WebService Request type message?
or how I can transform integer type message to WebService Request type message?
There are a bunch of ways to do this:
If you are mapping the request from another message, you can hard code it in the map - click on the field in the RHS of the Map Editor and set the hard coded value in the Value in the Property box
After creating a (dummy) request message, you can set the value using xpath() in an expression message assignment shape
xpath(myRequestMessage, "//*[local-name()='NameOfFieldHere']") = 3; // Or set to it your variable
If the field is distinguished in your schema, you can use the distinguished field instead of xpath, viz in an expression message assignment shape:
myRequestMessage.NameOfFieldHere = 3;
(And note if its a multipart message, then it will be myRequestMessage.Part.NameOfFieldHere OFC)
One disclaimer: I've assumed the WCF service request message is trivial, i.e. just a single integer field. If your message is large, using //local-name() ... isn't recommended, since
There may be more than one node with with the name NameOfFieldHere
The XSL parser used by BizTalk is slow and resource intensive when evaluating large xml documents with //
Biztalk Scheduler Adapter is really helpful in this case. It generates desired XML on predefined scheduled set by the user. So fill up your XML with hard coded values and receive them through this adapter.

mongo node driver object reference

In order to write an app handling the database responses I need to know the possible structures and values of the ubiquitous error parameter.
all the callbacks have:
function(err, res) ...
Does anyone know about the structure of the err object?
When provided to the callback, the err parameter contains an Error-based object. The name property of the object can be used to differentiate the types of errors, and the message property contains a string description of the error.
Looks like $err is usually a string type. See http://jp.wiki.mongodb.org/display/DOCS/Error+Handling+in+Mongo+Drivers

oData operation consumption with objective-C

I have a really simple WCF service operation GetCurrentBalance. It returns a decimal.
I also have the odatagen generated entity files included in the project, which contains an implementation of the GetCurrentBalance operation returning a string. Calling this method returns me an XML string with the desired value in it.
I also tried using executeServiceOperation method in the generated class and pass in the operation name as a parameter, the returned value again is the same XML string.
Is there a way to extract this value? Or do I have to write a custom parser for it?
Thanks in advance.
Without further informations, if the returned value is a formatted XML string you may try extracting the value using XPath queries, have a look at this to get you started

Serializing Exceptions WCF + Silverlight

I have a WCF service I use to submit bugs for my project. Snippet of the data class:
Private _exception As Exception
<DataMember()> _
Public Property Exception As Exception
Get
Return _exception
End Get
Set(ByVal value As Exception)
_exception = value
End Set
End Property
I have a Silverlight app that uses the WCF service to send any bugs home if and when they occur. This is the error I'm testing with:
Dim i As Integer = 5
i = i / 0
The problem is SL is banging on with this message:
System.ServiceModel.CommunicationException was unhandled by user code
Message=There was an error while trying to serialize parameter :bug. The InnerException message was 'Type 'System.OverflowException' with data contract name 'OverflowException:http://schemas.datacontract.org/2004/07/System' is not expected. 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 DataContractSerializer.'. Please see InnerException for more details.
Is there some trick to get a generic .NET Exception (any InnerException) to serialize properly? I'm not doing anything funky with the exception - it's just a plain 'ol exception
Thanks for any help.
I doubt very much that you can serialize a .NET-specific type like an Exception. I recommend you create your own class to hold the parts of the exception you want serialized.
This may be a problem with implicitly casting the OverflowException into a System.Exception.
The data contract serializer is very specific. This can be good and bad.
I would try just throwing a new System.Exception to see if this works OK.
If this is the case, you may need to dumb down the exception, creating a new System.Exception with the original exception message in it.
Or, like John said, you might have a better go of it if you create a custom error class that holds the exception info.