Pb de serialisation d'un objet métier avant traitement par une web method
Salut,
Je voudrais présenter un web service pouvant accepter n'importe quel objet. Cela parce qu'il est destiné à plusieurs client qui utilisent différents formats de données et différentes méthodes pour les envoyer.
Quel que soit les données qui arrivent elles sont sensées mettre un stock à jour.
Le comportement de l'application serait modifié en fonction d'un paramètre de type chaine "clientName".
Code:
1 2 3
|
[WebMethod]
public string HelloWorld(object obj, string clientName) |
Le but étant de ne pas avoir à développer 36 web services.
Ca compile, mais ne marche pas vraiment. Je n'ai que le protocole SOAP1.1 ou 1.2. Est-ce normal, quel en est la raison?
Deplus, j'ai une erreur à l'execution
Citation:
Erreur lors de la génération du document XML.
Bon, j'ajoute des détails:
La web method pour le test elle renvoi juste "done"
Code:
1 2 3 4 5
| [WebMethod]
public string HelloWorld(object obj, string clientName)
{
return "done";
} |
La procedure qui fait appel au web service
Code:
1 2 3 4 5 6 7
| private static void MaProc1()
{
Obj1 obj = new Obj1();
obj.ProId = 1;
obj.Nom = "toto";
Service1 srv = new Service1();srv.HelloWorld(obj, "toto");
} |
La classe Obj1
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| namespace Immobilis.EComm.BO
{
[Serializable]
public class Obj1
{
private int _proId;
public int ProId
{
get { return _proId; }
set { _proId = value; }
}
private string _nom;
public string Nom
{
get { return _nom; }
set { _nom = value; }
}
}
} |
Et pour finir, la trace
Citation:
System.InvalidOperationException was unhandled
Message="Erreur lors de la génération du document XML."
Source="System.Xml"
StackTrace:
à System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
à System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle)
à System.Web.Services.Protocols.SoapHttpClientProtocol.Serialize(SoapClientMessage message)
à System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
à ConsoleApplication1.localhost.Service1.HelloWorld(Object obj, String clientName) dans C:\Users\Julien\Documents\Visual Studio 2005\Projects\Solution2\ConsoleApplication1\Web References\localhost\Reference.cs:ligne 78
à ConsoleApplication1.Program.MaProc1() dans C:\Users\Julien\Documents\Visual Studio 2005\Projects\Solution2\ConsoleApplication1\Program.cs:ligne 53
à ConsoleApplication1.Program.Main(String[] args) dans C:\Users\Julien\Documents\Visual Studio 2005\Projects\Solution2\ConsoleApplication1\Program.cs:ligne 26
à System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()
A+