none
webinvoke put complex structure RRS feed

  • Question

  • Hi,

    I have the following declaration:

            [OperationContract]
            [WebInvoke(Method = "PUT", UriTemplate = "svcrVCIPutBellImages? images_in={images_in}")]
            String svcrVCIPutBellImages(VCI_Bell_Images[] images_in);

    Where the array is defined as:

           #region VCI_Bell_Images
            [DataContract]
            public class VCI_Bell_Images
            {
    
                public VCI_Bell_Images()
                {
                    this.acsAlarmType = " ";
                    this.sImage = null;
                    this.acsFileExtension = " ";
                    this.acsFileName = " ";
                }
    
                public VCI_Bell_Images(String acAlarmType, byte[] Image, String FileExtension)
                {
                    this.acsAlarmType = acAlarmType;
                    this.sImage = Image;
                    this.acsFileExtension = FileExtension;
                    this.acsFileName = "none";
                }
                public VCI_Bell_Images(String acAlarmType, byte[] Image, String FileName, String FileExtension)
                {
                    this.acsAlarmType = acAlarmType;
                    this.sImage = Image;
                    this.acsFileExtension = FileExtension;
                    this.acsFileName = FileName;
                }
                [DataMember]
                public String acAlarmType
                {
                    get { return this.acsAlarmType; }
                    set { this.acsAlarmType = value; }
                }
    
                [DataMember]
                public byte[] Image
                {
                    get { return this.sImage; }
                    set { this.sImage = value; }
                }
                [DataMember]
                public String FileExtension
                {
                    get { return this.acsFileExtension; }
                    set { this.acsFileExtension = value; }
                }
                [DataMember]
                public String FileName
                {
                    get { return this.acsFileName; }
                    set { this.acsFileName = value; }
                }
                private String acsAlarmType;
                private byte[] sImage;
                private String acsFileExtension;
                private String acsFileName;
            }
            #endregion


    Everything about this structure is string and byte arrays.

    QueryStringConverter is supposed to handle strings and byte arrays natively.

    But I get the errors:

    Server Error in '/' Application.
    
    Operation 'svcrVCIPutBellImages' in contract 'IVCIWCFRServices' has a query variable named 'images_in' of type 'VCIWCFRestfulServiceNS.VCI_Bell_Images[]', but type 'VCIWCFRestfulServiceNS.VCI_Bell_Images[]' is not convertible by 'QueryStringConverter'.  Variables for UriTemplate query values must have types that can be converted by 'QueryStringConverter'. 
      Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
     Exception Details: System.InvalidOperationException: Operation 'svcrVCIPutBellImages' in contract 'IVCIWCFRServices' has a query variable named 'images_in' of type 'VCIWCFRestfulServiceNS.VCI_Bell_Images[]', but type 'VCIWCFRestfulServiceNS.VCI_Bell_Images[]' is not convertible by 'QueryStringConverter'.  Variables for UriTemplate query values must have types that can be converted by 'QueryStringConverter'.
    
    Source Error: 
    
    
     An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
    
    Stack Trace: 
    
    
    
    [InvalidOperationException: Operation 'svcrVCIPutBellImages' in contract 'IVCIWCFRServices' has a query variable named 'images_in' of type 'VCIWCFRestfulServiceNS.VCI_Bell_Images[]', but type 'VCIWCFRestfulServiceNS.VCI_Bell_Images[]' is not convertible by 'QueryStringConverter'.  Variables for UriTemplate query values must have types that can be converted by 'QueryStringConverter'.]
       System.ServiceModel.Dispatcher.UriTemplateClientFormatter.Populate(Dictionary`2& pathMapping, Dictionary`2& queryMapping, Int32& totalNumUTVars, UriTemplate& uriTemplate, OperationDescription operationDescription, QueryStringConverter qsc, String contractName) +1070
       System.ServiceModel.Web.WebServiceHost.IsRawContentMapperCompatibleDispatchOperation(OperationDescription operation, Int32& numStreamOperations) +184
       System.ServiceModel.Web.WebServiceHost.SetRawContentTypeMapperIfNecessary(ServiceEndpoint endpoint, Boolean isDispatch) +244
       System.ServiceModel.Web.WebServiceHost.OnOpening() +434
       System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +265
       System.ServiceModel.Channels.CommunicationObject.Open() +36
       System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +90
       System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +598
    
    [ServiceActivationException: The service '/VCIWCFRServices' cannot be activated due to an exception during compilation.  The exception message is: Operation 'svcrVCIPutBellImages' in contract 'IVCIWCFRServices' has a query variable named 'images_in' of type 'VCIWCFRestfulServiceNS.VCI_Bell_Images[]', but type 'VCIWCFRestfulServiceNS.VCI_Bell_Images[]' is not convertible by 'QueryStringConverter'.  Variables for UriTemplate query values must have types that can be converted by 'QueryStringConverter'..]
       System.Runtime.AsyncResult.End(IAsyncResult result) +485948
       System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +174
       System.ServiceModel.Activation.AspNetRouteServiceHttpHandler.EndProcessRequest(IAsyncResult result) +6
       System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +129
    
      
    
    
    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34212  


    Ok, what do I have to do?

    Please advise

    Boyd


    But the inverse works fine:

         [OperationContract]
            [WebGet(UriTemplate = "svcrVCIGetBellImages")]
            VCI_Bell_Images[] svcrVCIGetBellImages();
    

    So I can GET a list of complex structures, but I cannot PUT the same structure!!!

    BDM

    • Edited by Boyd1 Wednesday, February 25, 2015 8:53 PM
    Wednesday, February 25, 2015 3:56 PM

Answers

  • Hi Boyd1,

    In my mind WCF UriTemplate does not support complex objects. So in this case you may need to stick with primary types from .NET. If you still want to use a complex object as parameter to your method, then maybe you need to drop the UriTemplate and pass your object using JSON.

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, February 26, 2015 4:24 AM
    Moderator