简体   繁体   中英

CloseQuoteRequest throwing exception

I am trying to close a quote in MSCRM using C# CloseQuoteRequest.

CloseQuoteRequest closeQuoteRequest = new CloseQuoteRequest()
{
    QuoteClose = new QuoteClose()
    {
        QuoteId = quote.ToEntityReference(),
        Subject = "Quote Close " + DateTime.Now.ToString(),
    },
    Status = new OptionSetValue(-1),
    RequestName = "CloseQuote",
};
Service.Execute(closeQuoteRequest);

I am getting the error;

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:request . The InnerException message was 'Error in line 1 position 711. Element ' http://schemas.datacontract.org/2004/07/System.Collections.Generic:value ' contains data from a type that maps to the name 'CRM.Entities.Entities:QuoteClose'. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'QuoteClose' and namespace 'CRM.Entities.Entities'.'. Please see InnerException for more details.

There is no inner exception for me to see.

Code sample from MSDN don't have RequestName = "CloseQuote" property being set as it's not needed. Remove it.

// Close the quote
CloseQuoteRequest closeQuoteRequest = new CloseQuoteRequest()
{
    QuoteClose = new QuoteClose()
    {
        QuoteId = closeQuote.ToEntityReference(),
        Subject = "Quote Close " + DateTime.Now.ToString()
    },
    Status = new OptionSetValue(-1)
};
_serviceProxy.Execute(closeQuoteRequest);

RequestName
Gets or sets the name of the request. Required, but is supplied by derived classes.(Inherited from OrganizationRequest.)

Status
The Status property corresponds to the Quote.StatusCode attribute. It is shown as “Status Reason” in the Microsoft Dynamics 365 application. If you set the value of this property to -1, the system sets the appropriate corresponding status value.

I don't know why this was the case but adding .ToEntity() to the QuoteClose Entity worked.

CloseQuoteRequest closeQuoteRequest = new CloseQuoteRequest()
{
    QuoteClose = new QuoteClose()
    {
        QuoteId = quote.ToEntityReference(),
        Subject = "Quote Close " + DateTime.Now.ToString(),
    }.ToEntity<Entity>(),
    Status = new OptionSetValue(-1),
    RequestName = "CloseQuote",
};
Service.Execute(closeQuoteRequest);
WinQuoteRequest winQuoteRequest = new WinQuoteRequest();
Entity wonQuoteClose = new Entity("quoteclose");
wonQuoteClose.Attributes["quoteid"] = new EntityReference("quote", id);
wonQuoteClose.Attributes["subject"] = "Quote Close" + DateTime.Now.ToString();
winQuoteRequest.QuoteClose = wonQuoteClose;
winQuoteRequest.Status = new OptionSetValue(-1);
service.Execute(winQuoteRequest);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM