Error when updating custom no on sales order via web service

gmorkengmorken Member Posts: 38
edited 2012-09-07 in NAV Three Tier
Hello,
I have a strange problem happening when I try to update/set customer no on sales order
Creating the order via web services works ok
Dynamics NAV 2009 R2

Heres the code.
       // Create Service Reference
        var service = new Order.Order_Service();
        service.UseDefaultCredentials = true;

        // Create the Order header
        var newOrder = new Order.Order();
        
        newOrder.No = "WEB12035";

        service.Create(ref newOrder);

        Order.Order getOrder = new Order.Order();
        getOrder = service.Read("WEB12035");
        getOrder.Sell_to_Customer_No = "1004003";

        service.Update(ref getOrder);
       
service.Update(ref getOrder) generates Soapexception "Object reference is not set to an instance of an object"
Service:
User:
Type: System.NullReferenceException
Message: Object reference not set to an instance of an object.
StackTrace:
at Microsoft.Dynamics.Nav.Service.WebServices.ServiceForm.WriteField(MetaControl control, String value)
at Microsoft.Dynamics.Nav.Service.WebServices.ServiceFormXmlAdapter.WriteEntity(XmlElement entity)
at Microsoft.Dynamics.Nav.Service.WebServices.ServiceFormXmlAdapter.ModifyEntity(XmlElement entity, Boolean versionCheckHasBeenDone)
at Microsoft.Dynamics.Nav.Service.WebServices.ServiceFormXmlAdapter.<>c__DisplayClass24.<Update>b__1f()
at Microsoft.Dynamics.Nav.Runtime.NavConnection.TransactionScope(TransactedCode code)
at Microsoft.Dynamics.Nav.Service.WebServices.ServiceFormXmlAdapter.Update(XmlElement input, XmlWWriter output)
Source: Microsoft.Dynamics.Nav.Service.WebServices
Service: MicrosoftDynamicsNavWS

Type: System.Reflection.TargetInvocationException
Message: Exception has been thrown by the target of an invocation.
StackTrace:
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.Dynamics.Nav.Service.WebServices.ServiceFormXmlAdapter.<>c__DisplayClass3d.<Microsoft.Dynamics.Nav.Service.WebServices.IXmlRequestHandler.Dispatch>b__39()
at Microsoft.Dynamics.Nav.Service.WebServices.XmlWWriter.SetNamespace(QNamespace namespace, XmlCallback nodeHandler)
at Microsoft.Dynamics.Nav.Service.WebServices.ServiceFormXmlAdapter.Microsoft.Dynamics.Nav.Service.WebServices.IXmlRequestHandler.Dispatch(XmlElement input, XmlWWriter output)
at Microsoft.Dynamics.Nav.Service.WebServices.SoapHandler.<>c__DisplayClass4.<Microsoft.Dynamics.Nav.Service.WebServices.IXmlRequestHandler.Dispatch>b__0()
at Microsoft.Dynamics.Nav.Service.WebServices.SoapHandler.<>c__DisplayClass9.<BuildEnvelop>b__8()
at Microsoft.Dynamics.Nav.Service.WebServices.XmlWWriter.Element(String name, XmlCallback elementHandler)
at Microsoft.Dynamics.Nav.Service.WebServices.SoapHandler.<>c__DisplayClass9.<BuildEnvelop>b__7()
at Microsoft.Dynamics.Nav.Service.WebServices.XmlWWriter.Element(String name, XmlCallback elementHandler)
at Microsoft.Dynamics.Nav.Service.WebServices.SoapHandler.<>c__DisplayClass9.<BuildEnvelop>b__6()
at Microsoft.Dynamics.Nav.Service.WebServices.XmlWWriter.SetNamespace(QNamespace namespace, XmlCallback nodeHandler)
at Microsoft.Dynamics.Nav.Service.WebServices.SoapHandler.BuildEnvelop(XmlWWriter output, ContentHandler handler)
at Microsoft.Dynamics.Nav.Service.WebServices.SoapHandler.Microsoft.Dynamics.Nav.Service.WebServices.IXmlRequestHandler.Dispatch(XmlElement input, XmlWWriter output)
at Microsoft.Dynamics.Nav.Service.WebServices.ServiceBroker.DispatchSoap(UrlParser relivantURLPart, XmlReader input, TextWriter output)
at Microsoft.Dynamics.Nav.Service.WebServices.ServiceBroker.Invoke(Boolean isSoapMessage, String serviceName, Uri url, XmlReader input, TextWriter output, String sid)
Source: mscorlib
Type: System.NullReferenceException
Message: Object reference not set to an instance of an object.
StackTrace:
at Microsoft.Dynamics.Nav.Service.WebServices.ServiceForm.WriteField(MetaControl control, String value)
at Microsoft.Dynamics.Nav.Service.WebServices.ServiceFormXmlAdapter.WriteEntity(XmlElement entity)
at Microsoft.Dynamics.Nav.Service.WebServices.ServiceFormXmlAdapter.ModifyEntity(XmlElement entity, Boolean versionCheckHasBeenDone)
at Microsoft.Dynamics.Nav.Service.WebServices.ServiceFormXmlAdapter.<>c__DisplayClass24.<Update>b__1f()
at Microsoft.Dynamics.Nav.Runtime.NavConnection.TransactionScope(TransactedCode code)
at Microsoft.Dynamics.Nav.Service.WebServices.ServiceFormXmlAdapter.Update(XmlElement input, XmlWWriter output)
Source: Microsoft.Dynamics.Nav.Service.WebServices

Comments

  • ufukufuk Member Posts: 514
    Why don't you assign customer no to the previously created order object as following?
           // Create Service Reference
            var service = new Order.Order_Service();
            service.UseDefaultCredentials = true;
    
            // Create the Order header
            var newOrder = new Order.Order();
            
            newOrder.No = "WEB12035";
            service.Create(ref newOrder);
            
            newOrder.Sell_to_Customer_No = "1004003";
            service.Update(ref newOrder);
           
    
    Ufuk Asci
    Pargesoft
  • gmorkengmorken Member Posts: 38
    I have tried that also but same result
  • ufukufuk Member Posts: 514
    It works for me but with the standart objects. So, is the Order object standard sales order page? If not, you may try your code with standard objects. I think modified insert trigger of sales header table or customer no validation can cause this.
    And when you debug, is order object null on Update line?
    Ufuk Asci
    Pargesoft
  • gmorkengmorken Member Posts: 38
    Hello,
    Thanks for looking into this.
    I have debugged oninsert and customer no validation trigger in the table. I beleive its the record36.cs source file. No problem there.

    I think the problem is in the generated proxy class for the web service. In my event log it says:

    Object reference not set to an instance of an object.
    Line 393: [System.Web.Services.Protocols.SoapDocumentMethodAttribute("urn:microsoft-dynamics-schemas/page/order:Update", RequestNamespace="urn:microsoft-dynamics-schemas/page/order", ResponseElementName="Update_Result", ResponseNamespace="urn:microsoft-dynamics-schemas/page/order", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]

    Line 394: public void Update(ref Order Order) {
    Line 395: object[] results = this.Invoke("Update", new object[] {
    Line 396: Order});
    Line 397: Order = ((Order)(results[0]));


    Source File: c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\navweborder002\311bdc07\37869510\App_WebReferences.qsq7mnha.0.cs

    Is it possible to debug the proxy?
  • ufukufuk Member Posts: 514
    I don't think so. Have you tried doing order creation and modification with the same user within NAV (not using a ws)? If an error occurs, this can give you an idea.
    Ufuk Asci
    Pargesoft
Sign In or Register to comment.