MessageResponse Cannot be null in MessageResponse

Topics: Service Factory Modeling Edition Forum
Mar 12, 2009 at 9:24 PM
Edited Mar 13, 2009 at 1:22 AM
I have trouble with serviceContract.diagram

I think any service in this way

   -> Servicecontract
-> Operation
-> MessageResponse (Primitive type)
-> MessageRequest (datacontract)

valid diagram and generate the code
is generated and the service proxy
makes access to its data and its implementation
So far I tested a unit and runs well
but when I do this test is the method of the proxy ahi me
said that 


Test method UnitTesting.OrdenCompraContractClientTest.CreateOrdenCompraTest threw exception: System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: El valor no puede ser nulo.

Nombre del parámetro: Internal Error: The instance of the MessageContract cannot be null in





and what other services they have created if it works

able clues to solve

Mar 12, 2009 at 9:59 PM
The answer may sound simple but consider checking if you are returning some not null value from your service operation, in this case, a valid instance of your response type. 
Mar 13, 2009 at 1:40 AM
Returns a primitive type that is Uint64 as in this case is the CveOrdenCompra and that is how it assigns it to the messageresponse
Mar 13, 2009 at 2:16 AM
Can you post the code of your operation that is returning the MessageContract instance with the right values assigned?

Mar 13, 2009 at 3:34 AM

This Method for create ordencompra

ulong CreateOrdenCompra(OrdenCompra ordenCompraNueva) {










ulong claveNueva;




claveNueva = ordenCompraDA.Insert(ordenCompraNueva);

ordenCompraNueva.CveOrden = claveNueva;

centroCostoDA.Transaction = ordenCompraDA.Transaction;


delegate(CentroCosto centroCosto) {




bienServicioDA.Transaction = ordenCompraDA.Transaction;


delegate(BienServicioAsignado bienServicioA) {


bienServicioDA.Insert(bienServicioA, ordenCompraNueva);




return claveNueva;




catch (Exception ex)





throw ex;




this class RequestOrdenCompra.cs




Genworth.Compras.Svc.WCF.DataContracts.OrdenCompra ordenCompraNueva;




MessageBodyMember(Name = "OrdenCompraNueva")]



public Genworth.Compras.Svc.WCF.DataContracts.OrdenCompra OrdenCompraNueva




get { return ordenCompraNueva; }



set { ordenCompraNueva = value; }



this class ResponseOrdenCompra.cs



ulong cveOrdenCompraNueva;




MessageBodyMember(Name = "CveOrdenCompraNueva")]



public ulong CveOrdenCompraNueva




get { return cveOrdenCompraNueva; }



set { cveOrdenCompraNueva = value; }



this class OrdenCompraImplementation.cs


public override ResponseOrdenCompra CreateOrdenCompra(RequestOrdenCompra request)




ResponseOrdenCompra response = new ResponseOrdenCompra();


response.CveOrdenCompraNueva = ordenCompraBP.CreateOrdenCompra(request.OrdenCompraNueva);


return response;



this class IOrdenCompraContract.cs


ServiceContract(Namespace = "", Name = "OrdenCompraContract", SessionMode = WCF::SessionMode.Allowed, ProtectionLevel = ProtectionLevel.None )]



public partial interface IOrdenCompraContract




OperationContract(IsTerminating = false, IsInitiating = true, IsOneWay = false, AsyncPattern = false, Action = "", ProtectionLevel = ProtectionLevel.None)]



ResponseOrdenCompra CreateOrdenCompra(Genworth.Compras.Svc.WCF.MessageContracts.RequestOrdenCompra request);



this  class OrdenCompraProxy.cs


public ulong CreateOrdenCompra(Genworth.Compras.Svc.WCF.Client.OrdenCompraProxy.OrdenCompra OrdenCompraNueva)




RequestOrdenCompra inValue = new Genworth.Compras.Svc.WCF.Client.OrdenCompraProxy.RequestOrdenCompra();


inValue.OrdenCompraNueva = OrdenCompraNueva;


ResponseOrdenCompra retVal = ((Genworth.Compras.Svc.WCF.Client.OrdenCompraProxy.OrdenCompraContract)(this)).CreateOrdenCompra(inValue);



return retVal.CveOrdenCompraNueva;



Mar 13, 2009 at 3:38 AM





public void CreateOrdenCompraTest()








OrdenCompraContractClient target = new OrdenCompraContractClient(); // TODO: Initialize to an appropriate value




OrdenCompra OrdenCompraNueva = new OrdenCompra(); // TODO: Initialize to an appropriate value


OrdenCompraNueva.Solicitud =

new SolicitudInsumo();


OrdenCompraNueva.Solicitud.Clave = 115;


OrdenCompraNueva.UsuarioValidoBienServicio =

new Empleado();


OrdenCompraNueva.UsuarioValidoBienServicio.Clave = 1;

OrdenCompraNueva.FechaSolicitud = System.



OrdenCompraNueva.CompradorGPPI =



OrdenCompraNueva.FechaVencimientoEntrega = System.



OrdenCompraNueva.EmpleadoSolicitante =

new Empleado();


OrdenCompraNueva.EmpleadoSolicitante.Clave = 3;

OrdenCompraNueva.RamoAfectoSolicitante =

new RamoAfectoSolicitante();


OrdenCompraNueva.RamoAfectoSolicitante.Clave = 4;

OrdenCompraNueva.ProveedorAsignado =

new Proveedor();


OrdenCompraNueva.ProveedorAsignado.Clave = 5;

OrdenCompraNueva.CondicionPago =

new CondicionPago();


OrdenCompraNueva.CondicionPago.Clave = 2;

OrdenCompraNueva.EstatusSolicitudRequerimiento =



OrdenCompraNueva.EstatusOrdenCompra =






OrdenCompraNueva.ListaCentrosCosto =

new ListaCentrosCosto();



CentroCosto objCC = new CentroCosto();


objCC.Clave = 3;





OrdenCompraNueva.ListaBienesServiciosAsignados =

new ListaBienesServiciosAsignados();



BienServicioAsignado objBSa = new BienServicioAsignado();



BienServicio objBS = new BienServicio();


objBS.FinContrato = System.



objBS.InicioContrato = System.



objBS.Clave = 1;

objBSa.BienServicio = objBS;

objBSa.CantidadSolicitada = 2;

objBSa.Importe = 200;

objBSa.PrecioUnitario = 100;



ulong expected = 93; // TODO: Initialize to an appropriate value



ulong actual;


actual = target.CreateOrdenCompra(OrdenCompraNueva);


Assert.AreEqual(expected, actual);





catch (System.Exception ex)




throw ex;




HUgo L.

Mar 13, 2009 at 10:01 AM

I could not find the initialization for "ordenCompraBP" in operation "CreateOrdenCompra" in OrdenCompraImplementation.cs
This si the line that calls:

response.CveOrdenCompraNueva = ordenCompraBP.CreateOrdenCompra(request.OrdenCompraNueva);

It seems that the error is being thrown from this line.

Mar 13, 2009 at 5:41 PM



partial class OrdenCompraImplementation:OrdenCompraServiceBase




protected OrdenCompraBP ordenCompraBP = new OrdenCompraBP();





public override ResponseOrdenCompra CreateOrdenCompra(RequestOrdenCompra request)




ResponseOrdenCompra response = new ResponseOrdenCompra();


response.CveOrdenCompraNueva = ordenCompraBP.CreateOrdenCompra(request.OrdenCompraNueva);


return response;




already revice and if this initialized

here the rare thing is that in servicecontract.model
I take it into another service to adopt (InsumoService) and if it works but in
service that corresponds to him does not work

until the implementation it does well but when I already want to consume
the one of the Proxy is there when it sends the error in the service of OrdenCompraService

Mar 13, 2009 at 10:57 PM
I would try to debug the service and check just before returning from the failing operation.
Mar 18, 2009 at 7:55 PM
Thanks Hernan the problem was solved and thanks for tips that were helful