locked
Issue with params for a custom service operation RRS feed

  • Question

  • Hi!
    I am currently building a custom OData service (untyped). In this service I would like to add a service method "Foo". It should receive one string parameter "Code". Here is the code snippet with which I want to add the parameter to the service's metadata:
    public override IDataServiceMetadataProvider GetMetadataProvider(Type dataSourceType)
    {
     var metadataProvider = new CustomDataServiceMetadataProvider();
    
     ...
    
     metadataProvider.AddServiceOperation(new ServiceOperation(
      "Foo",
      ServiceOperationResultKind.Enumeration,
      myResourceType,
      myResourceSet,
      "GET",
      new[] {
        new ServiceOperationParameter("Code", new ResourceType(typeof(string), ResourceTypeKind.Primitive, null, "Namespace", "Code", false))
      }));
    
    
     return metadataProvider;
    }
    
    If I run this code I receive the following argument exception: 'Primitive' is not a valid value for resourceTypeKind. Parameter name: resourceTypeKind
    If I pass anything else than ResourceTypeKind.Primitive to the ctor of ServiceOperationParameter I get an exception that only primitive types are supported as parameters.
    Any idea what I do wrong? Any link to a sample with a custom service provider with custom operations?
    BTW - the operation works fine if I drop all parameters.
    Kind regards,
    Rainer.

    Rainer
    Tuesday, May 24, 2011 10:02 AM

Answers

  • Found the solution myself. You have to use ResourceType.GetPrimitiveResourceType(typeof(string)) instead of new ResourceType(...) and everything works like a charm.
    Rainer
    Tuesday, May 24, 2011 12:10 PM

All replies

  • Found the solution myself. You have to use ResourceType.GetPrimitiveResourceType(typeof(string)) instead of new ResourceType(...) and everything works like a charm.
    Rainer
    Tuesday, May 24, 2011 12:10 PM
  • Hi Rainer,

    I’m glad to hear that you got it working. Thank you for sharing your experience here.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, May 25, 2011 1:10 AM
    Moderator
  • Hi Rainer,

    I'm about the same point you were here so thanks for the heads up about creating the resourceType. I'm trying to create the ResourceSet using the string Resource type I've creating using GetPromativeResourceType but it expects an EntityType.

    The ServiceOperation is simply going to be string Hello() { return "world";} at the moment.

    Can you suggest where I might be going wrong.

    Thanks,
    Owen 

    Friday, September 2, 2011 9:32 AM