.NET Framework Bookmark and Share   
 index > Windows Communication Foundation > Known Types - Serialization
 

Known Types - Serialization

Hi

I am pretty sure I have a problem with Serialization, because I can Debug the WCF Service but when it gets returned to the client, a Communication Exception is thrown:

"An error occurred while receiving the HTTP response to http://localhost:8000/. 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."

This happens at the following call:

_provider is the channel

IQMSSession session = _provider.GetSession(...);

calls the WCF Service and creates a new QMSSession(...)

in the QMSSession constructor
_service is a IQMSService Interface

_service = QMSService.Create(this); // calls a Static method in the QMSService class, and passes itself as parameter

Static method Create :

return new QMSService(new InternalServiceContext(session));

The InternalServiceContext Constructor only does this:

_clientid = session.ClientID;
_session = session;

The QMSService Constructor

private QMSService(InternalServiceContext context)
{
Context = context;

_licensingService = new QMSLicensingService(Context);
_workflowservice = new QMSWorkflowService(Context);
_usermanagementservice = new QMSUserManagementService(Context);
}

The important information is:
When I comment out everthing in the QMSService constructor the Communication Exception does NOT occur.
When only Context = context; is not commented out the Communication Exception does occur again.

So I guess the Problem is to do with the Serialization of InternalServiceContext in QMSService.

Context is a protected InternalServiceContext variable.

All classes
InternalServiceContext, QMSSession, QMSService
are all Serializable and marked in the WCF Service Interface as i.e. ServiceKnownType(typeof(InternalServiceContext))

Does anybody know what I mgiht be doing wrong?

Thanks a lot

Thorsten
Thorsten901
Hi Thorsten,

This might help you - http://nirajrules.wordpress.com/2009/08/26/wcf-serializers-xmlserializer-vs-datacontratserializer-vs-netdatacontractserializer/

If you are trying to return a sub type from a hosted contract the only the way you can do that is by sharing implementations with both client & server. Though I don't see circular references as an issue here, but in case that's troubling you - 'preserveObjectReferences' needs to be set to true while construction of DataContractSerializer happens.

Niraj
[http://nirajrules.wordpress.com]
Niraj Rules
Ok I think I have a different Problem:

The InternalServiceContext is referencing the QMSSession, and QMSSession is referencing QMSService, while QMSService is then again referencing InternalServiceContext.

So it always goes around.
And when the Serialization happens I believe, that this cannot work, because references do not work in Serialization. A copy is always made of the referenced object, so the Serializer is making copies all the time and running in a circle.

Can anybody confirm what I am thinking?
Am I thinking in the right direction?

If yes, is there a simple solution for this? Can I use some different Serializer?
Or do I have to rework my program with the references working different?

Thanks a lot for your help

Thorsten
Thorsten901
Can you please publish the Service and Operation contracts?

Thanks,
-Phani
Phani_tpk
[ServiceContract(Namespace = "http://Bitworks.XMS.WCF.ServiceContracts", SessionMode = SessionMode.Required)
, ServiceKnownType(typeof(QMSService)), ServiceKnownType(typeof(QMSSession)),ServiceKnownType(typeof(DSReader))
, ServiceKnownType(typeof(Guid)), ServiceKnownType(typeof(bo.Chapter)), ServiceKnownType(typeof(QMSWorkflowService))
, ServiceKnownType(typeof(QMSUserManagementService)), ServiceKnownType(typeof(QMSLicensingService)), ServiceKnownType(typeof(DSUserInfo))
, ServiceKnownType(typeof(DSResponsible)), ServiceKnownType(typeof(ArrayList)), ServiceKnownType(typeof(DSVersion))
, ServiceKnownType(typeof(List<Guid>)), ServiceKnownType(typeof(DSClientInfos)), ServiceKnownType(typeof(DSChapter))
, ServiceKnownType(typeof(DSDocument)), ServiceKnownType(typeof(DSSearchResult)), ServiceKnownType(typeof(DSChapterDocuments))
, ServiceKnownType(typeof(DataSet)), ServiceKnownType(typeof(DSLog)), ServiceKnownType(typeof(DSFile))
, ServiceKnownType(typeof(DSFolderObject)), ServiceKnownType(typeof(DSPicture)), ServiceKnownType(typeof(DSPublicObject))
, ServiceKnownType(typeof(DSRepositorySearchResult)), ServiceKnownType(typeof(DSDocumentReviewStatus))
, ServiceKnownType(typeof(DSMyDocumentVersions))
, ServiceKnownType(typeof(DSMyDocumentReviews)), ServiceKnownType(typeof(Hashtable)), ServiceKnownType(typeof(decimal))
, ServiceKnownType(typeof(DSVersionComment)), ServiceKnownType(typeof(dsToDo)), ServiceKnownType(typeof(Dictionary<int,int>))
, ServiceKnownType(typeof(VersionContent)), ServiceKnownType(typeof(DSMyDocumentVersionsComments))
, ServiceKnownType(typeof(PDFPrintJobStateExchange))
, ServiceKnownType(typeof(StructureMetrics)), ServiceKnownType(typeof(GetClass)), ServiceKnownType(typeof(TTService))
, ServiceKnownType(typeof(InternalServiceContext)), ServiceKnownType(typeof(ServiceObjectBase))
, ServiceKnownType(typeof(KeyValuePair<DateTime, string>[]))
, ServiceKnownType(typeof(BitworksLicenseService)), ServiceKnownType(typeof(IBitworksLicense))
, ServiceKnownType(typeof(TestInternalServiceContext))]

public interface IQMSSessionProvider
{
[OperationContract]
IQMSSession GetSession(enRequestorType requestor, Guid userID, string userName, string userHost, string webSessionID);

[OperationContract]
IGetClass getGetClass(enRequestorType requestor, Guid userID, string userName, string userHost, string webSessionID);

[OperationContract]
int getInt(int d);

[OperationContract]
void AbandonSession(enRequestorType requestor, Guid sessionID); //use this for Logout
}

public enum enRequestorType { Proxy, CoreManager }

Thorsten901
Hi Thorsten,

This might help you - http://nirajrules.wordpress.com/2009/08/26/wcf-serializers-xmlserializer-vs-datacontratserializer-vs-netdatacontractserializer/

If you are trying to return a sub type from a hosted contract the only the way you can do that is by sharing implementations with both client & server. Though I don't see circular references as an issue here, but in case that's troubling you - 'preserveObjectReferences' needs to be set to true while construction of DataContractSerializer happens.

Niraj
[http://nirajrules.wordpress.com]
Niraj Rules
Thanks Niraj

The "preserveObjectReferences" solved the problem http://blogs.msdn.com/sowmy/archive/2006/06/06/618877.aspx
Thorsten901

You can use google to search for other answers

Custom Search

More Threads

• Check for WCF service
• Impersonation + WSHttpBinding + SSL
• custom encryption for message security
• non .NET data consumption on Client
• What is the best way to send large data from WCF service to Client
• Length of return data with WCF ??
• WCF WMI Events
• How to work-around the SVCUTIL, C#, Web Service Proxy code problem
• Preserve object reference between parameters
• Configuration Error