Récemment construit un WCF RESTful sur linux (CLI auto-hébergé), le programme est bon sous .NET mais échoue sous Mono. Strictement dit, la fonction utilisant GET et POST non-paramètre/mono-paramètre sont bonnes, il renvoie l'erreur 500 si poster plusieurs paramètres. Un autre problème est, si passer INVALID json à mono (dit, pas Content-Type dans l'en-tête, ou json format invalide), CLI s'arrêtera au lieu de jeter une exception et garder le service, c'est très fatal.Mono WCF Repos après plusieurs paramètres renvoie l'erreur (500)
Unhandled Exception: System.Xml.XmlException: Invalid comma before an end of object (4,1)
at System.Runtime.Serialization.Json.JsonReader.ReadContent (Boolean objectValue) [0x00000] in <filename unknown>:0
Veuillez nous aider, MERCI!
détails Première question ci-dessous
Mono Exception
Exception 'Element' is an invalid node type. Line 1, position 53. at System.Xml.XmlReader.ReadEndElement() [0x00000] in <filename unknown>:0
at System.ServiceModel.Dispatcher.WebMessageFormatter.DeserializeObject (System.Runtime.Serialization.XmlObjectSerializer serializer, System.ServiceModel.Channels.Message message, System.ServiceModel.Description.MessageDescription md, Boolean isWrapped, WebContentFormat fmt) [0x00000] in <filename unknown>:0
at System.ServiceModel.Dispatcher.WebMessageFormatter+WebDispatchMessageFormatter.DeserializeRequest (System.ServiceModel.Channels.Message message, System.Object[] parameters) [0x00000] in <filename unknown>:0
at System.ServiceModel.Description.WebHttpBehavior+DispatchPairFormatter.DeserializeRequest (System.ServiceModel.Channels.Message message, System.Object[] parameters) [0x00000] in <filename unknown>:0
at System.ServiceModel.Dispatcher.OperationInvokerHandler.BuildInvokeParams (System.ServiceModel.Dispatcher.MessageProcessingContext mrc, System.Object[]& parameters) [0x00000] in <filename unknown>:0
at System.ServiceModel.Dispatcher.OperationInvokerHandler.DoProcessRequest (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x00000] in <filename unknown>:0
at System.ServiceModel.Dispatcher.OperationInvokerHandler.ProcessRequest (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x00000] in <filename unknown>:0
at System.ServiceModel.Dispatcher.BaseRequestProcessorHandler.ProcessRequestChain (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x00000] in <filename unknown>:0
at System.ServiceModel.Dispatcher.BaseRequestProcessorHandler.ProcessRequestChain (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x00000] in <filename unknown>:0
at System.ServiceModel.Dispatcher.HandlersChain.ProcessRequestChain (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x00000] in <filename unknown>:0
at System.ServiceModel.Dispatcher.BaseRequestProcessor.ProcessRequest (System.ServiceModel.Dispatcher.MessageProcessingContext mrc) [0x00000] in <filename unknown>:0
App.config
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="Contracts.MyService" behaviorConfiguration="MEXBehavior">
<endpoint address="" binding="webHttpBinding" contract="Contracts.IMyService" behaviorConfiguration="MyRestBehavior" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
<host>
<baseAddresses>
<add baseAddress="http://192.168.1.99:18688/MyService"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="MyRestBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MEXBehavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> </startup></configuration>
Interface
[ServiceContract]
public interface IMyService
{
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "Ping")]
bool Ping();
[OperationContract]
[WebInvoke(Method = "POST",RequestFormat=WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle=WebMessageBodyStyle.Wrapped, UriTemplate="echo")]
string Echo(string name,string say);
}
mise en œuvre
[ServiceBehavior]
public class MyService:IMyService
{
public bool Ping()
{
return true;
}
public string Echo(string name, string say)
{
return name + " says: " + say;
}
}
Fiddler post
User-Agent: Fiddler
Host: 192.168.1.99:18688
Content-Length: 41
Content-Type: application/json
{
"name":"Alex",
"say":"Hello World"
}
Fiddler retour
HTTP/1.1 500 Internal Server Error
Content-Type: application/xml; charset=utf-8
Server: Mono-HTTPAPI/1.0
Date: Wed, 31 Jul 2013 04:31:20 GMT
Content-Length: 216
Connection: close
<Fault xmlns="http://schemas.microsoft.com/ws/2005/05/envelope/none"><Code><Value>Receiver</Value></Code><Reason><Text xml:lang="en-US">'Element' is an invalid node type. Line 1, position 53.</Text></Reason></Fault>
Pour les gars qui se lancent dans ce sujet, voir aussi http://stackoverflow.com/questions/18039476/how-to-debug-wcf-when-json-deserialize-fail – zhuchun
J'ai eu exactement le même problème lors du portage un service WCF hébergé par asp.net en mono. –