In the last 10 days, I have been redeveloping cs architecture software based on WCF. I have encountered many problems and recorded them.

  1. When a client of WCF adds a service reference, the code is automatically generated under the new namespace. If you want to use the original data structure, you need to define the data structure independently and add project dependencies before adding service references. Refer to the link

  2. A default endpoint element that references the protocol “××” could not be found. This is a client configuration problem. You need to copy the contents of servicemodel in app.config generated automatically in client to app.config in main program. Refer to the link

  3. Symptom WCF IMetadataExchange XMLSerializers file not found is faulty during WCF loading. WCF internal errors can be ignored. Or check vs just my code.

  4. Problem: Normal, because the callback interface needs to be implemented on the client side, obviously the client test tool cannot test because it does not have the callback implementation. Refer to the link

  5. Add WCF service reference error. Solution: Use the WCF test tool to add endpoints (need to publish MEX). There are detailed reasons for failure in the HTML view: for example, DataContract feature is not added to the required data.

  6. Publishing service metadata: 1. Mex needs to add the contract as the service endpoint of IMetadataExchange. 2. Http – a Get. It is best to define all the base addresses of the desired mode in the base address, and WCF will take care of itself. Service references and the wcfTestClient tool cannot be added until the service metadata is exposed.

  7. When starting the service: XmlException: The name cannot start with a “<” character (hex value 0x3C). Possible cause: Rewrite app.config, configuration file error. Refer to the link

  8. The error is as follows: It seems that the protocol configuration is incorrect.

EndpointNotFoundException: 'no channel with acceptable operating "http://schemas.xmlsoap.org/ws/2004/09/transfer/Get'
There was no channel that could accept the message with action 'http://schemas.xmlsoap.org/ws/2004/09/transfer/Get'

Copy the code
  1. WCF cannot be derived from the special class “System.multicastDelegate”; interfaces defined in WCF are not allowed to use this type parameter.

  2. A problem where OperationContext is NULL in an interface service implementation with a callback

  • It is possible that the callback is not properly defined because the callback interface does not define the operation [OperationContract].
  • Please note this sentence !!!! OperationContext is populated by information about the client when an operation call is made. The OperationContext must be obtained in the function called by the client to the server. Refer to the link
  • The object to get the OperationContext must be a reference link created by WCF through serviceHost
  1. An exception occurs when calling back:
$exception {"Unable to communication object System. The ServiceModel. Channels. ServiceChannel used in communication, because it has been suspended."} System.ServiceModel.CommunicationObjectAbortedException
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
Copy the code

Rebuild the project and resolve after updating the service reference.

  1. The exceptions are as follows. Cause: If the parameter is object, ServiceKnowType must be declared as a true type otherwise the above error will be reported. (It is best not to use object).
- $exception {Error trying to serialize parameter Wayeal.smartlab.qPCR: sender. InnerException News is a "data protocol name for" qPCR:http://schemas.datacontract.org/2004/07Lab.Plugin.CComponent.WayealDevice.qPCR "type" SmartLab. Plugin. CCom Ponent. WayealDevice. QPCR. QPCR "is not the required type. Consider using DataContractResolver (if you are using DataContractSerializer), or adding any unknown types statically to the list of known types. For example, you can use the KnownTypeAttribute attribute or add unknown types to the list of known types passed to the serializer." . For more information, see InnerException.} System.ServiceModel.CommunicationException
Copy the code
  1. The following exception occurred when calling the interface:
System.Xml.XmlException
HResult=0x80131940Message= The name cannot be a "<" character (hexadecimal value)0x3C) at the beginning. Source=System.Xml StackTrace: at System.Xml.XmlConvert.VerifyNCName(String name, ExceptionType exceptionType) This exception was originally thrown atthis call stack:
System.Xml.XmlConvert.VerifyNCName(string, System.Xml.ExceptionType)
Copy the code

WCF internal exception does not affect service invocation. Check only my code can be ignored

  1. Use ints instead of enumerations. Enumerating the ServiceKnowType declaration generates a client string.

  2. (Shared by others) If the service client that invokes WCF sends the message normally, and the server receives the message normally, but the client returns Null, the service contract may be updated, and the client and server do not correspond.

16. The smallest WCF callback example: adamprescott.net/2012/08/15/…

  1. Error serializing, internal exception is
Data protocol named "ArrayOfKeyValueOfanyTypeanyType: HTTP:/ / schemas.microsoft.com/2003/10/Serialization/Arrays "type" System. Collections. The Hashtable "is not the required type
Copy the code

Reason: Since Hashtable is not strongly typed, it actually uses Object internally to store data, so when the data is transferred to the other end, the element type cannot be correctly determined and deserialized. Reference: social.msdn.microsoft.com/Forums/sqls… There are three solutions:

  • You need to specify the actual type by adding the KnownType attribute to the class that contains the Hashtable type attribute. Such as:
[DataContract]
public class Book{} [DataContract]
public class Magazine{} [DataContract]
[KnownType(typeof(Book))]
[KnownType(typeof(Magazine))]
public class LibraryCatalog{[DataMember]
System.Collections.Hashtable theCatalog;
}
Copy the code

See msdn.microsoft.com/en-us/libra…

  • Handwriting serialization method, see << family parsing WCF >>.
  • Convert a Dictionary < TKey, TValue >.
  • Convert directly to string