MessageResponse Cannot be null in MessageResponse

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

I think any service in this way

service
   -> 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 




<dir>

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

http://genworthseguros.com/types/2009/OrdenCompraContract/CreateOrdenCompraResponse..

 

<dir></dir>

 

</dir>

and what other services they have created if it works

able clues to solve

greetings
Developer
Mar 12, 2009 at 8: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 12: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
Developer
Mar 13, 2009 at 1:16 AM
Can you post the code of your operation that is returning the MessageContract instance with the right values assigned?

Thanks,
Hernan
Mar 13, 2009 at 2:34 AM

This Method for create ordencompra

public
ulong CreateOrdenCompra(OrdenCompra ordenCompraNueva) {

 

 

try

 

 

 

 

{

 

ulong claveNueva;

 

ordenCompraDA.CreateTransaction();

 

claveNueva = ordenCompraDA.Insert(ordenCompraNueva);

ordenCompraNueva.CveOrden = claveNueva;

centroCostoDA.Transaction = ordenCompraDA.Transaction;

ordenCompraNueva.ListaCentrosCosto.ForEach(

delegate(CentroCosto centroCosto) {

 

centroCostoDA.Insert(centroCosto,ordenCompraNueva);

});

bienServicioDA.Transaction = ordenCompraDA.Transaction;

ordenCompraNueva.ListaBienesServiciosAsignados.ForEach(

delegate(BienServicioAsignado bienServicioA) {

 

bienServicioDA.Insert(bienServicioA, ordenCompraNueva);

});

ordenCompraDA.CommitTransaction();

 

return claveNueva;

 

}

 

catch (Exception ex)

 

{

ordenCompraDA.CancelTransaction();

 

throw ex;

 

}

}

this class RequestOrdenCompra.cs

 

private

 

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

 

 

[WCF::

MessageBodyMember(Name = "OrdenCompraNueva")]

 

 

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

 

{

 

get { return ordenCompraNueva; }

 

 

set { ordenCompraNueva = value; }

 

}



this class ResponseOrdenCompra.cs

private

 

ulong cveOrdenCompraNueva;

 

 

[WCF::

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

[WCF::

ServiceContract(Namespace = "http://genworthseguros.com/types/2009", Name = "OrdenCompraContract", SessionMode = WCF::SessionMode.Allowed, ProtectionLevel = ProtectionLevel.None )]

 

 

public partial interface IOrdenCompraContract

 

{

[WCF::

OperationContract(IsTerminating = false, IsInitiating = true, IsOneWay = false, AsyncPattern = false, Action = "http://genworthseguros.com/types/2009/OrdenCompraContract/CreateOrdenCompra", ProtectionLevel = ProtectionLevel.None)]

 

Genworth.Compras.Svc.WCF.MessageContracts.

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

 

}



this  class OrdenCompraProxy.cs

 

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

 

{

Genworth.Compras.Svc.WCF.Client.OrdenCompraProxy.

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

 

inValue.OrdenCompraNueva = OrdenCompraNueva;

Genworth.Compras.Svc.WCF.Client.OrdenCompraProxy.

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

 

 

return retVal.CveOrdenCompraNueva;

 

}

Mar 13, 2009 at 2:38 AM

[

TestMethod()]

 

 

public void CreateOrdenCompraTest()

 

{

 

try{

 

 

 

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.

DateTime.Now;

 

OrdenCompraNueva.CompradorGPPI =

CompradorGPPI.PI;

 

OrdenCompraNueva.FechaVencimientoEntrega = System.

DateTime.Now;

 

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 =

EstatusSolicitud.PendientePorAprobar;

 

OrdenCompraNueva.EstatusOrdenCompra =

EstatusOrdenCompra.Creada;

 

 

//--

 

OrdenCompraNueva.ListaCentrosCosto =

new ListaCentrosCosto();

 

 

CentroCosto objCC = new CentroCosto();

 

objCC.Clave = 3;

OrdenCompraNueva.ListaCentrosCosto.Add(objCC);

 

//--

 

OrdenCompraNueva.ListaBienesServiciosAsignados =

new ListaBienesServiciosAsignados();

 

 

BienServicioAsignado objBSa = new BienServicioAsignado();

 

 

BienServicio objBS = new BienServicio();

 

objBS.FinContrato = System.

DateTime.Now.Date;

 

objBS.InicioContrato = System.

DateTime.Now.Date;

 

objBS.Clave = 1;

objBSa.BienServicio = objBS;

objBSa.CantidadSolicitada = 2;

objBSa.Importe = 200;

objBSa.PrecioUnitario = 100;

OrdenCompraNueva.ListaBienesServiciosAsignados.Add(objBSa);

 

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;

 

}

}


thanks
HUgo L.

Developer
Mar 13, 2009 at 9: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 4:41 PM

public

 

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

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

Greetings!!!!