0

I'm building a REST API for our application. So far, the basics work. I can connect to the service, and it will invoke commands. However, in one of my methods, there is a parameter called (string) luceneQuery, and no matter where I put the method parameter, or what I type in the URL parameter, it is always null or empty.

I honestly can't figure this one out, and I've been having a go at it for a couple of hours; even Google has been putting me off.

Here is the route I'm using:

public const string SearchRoute = "/search/{domain}/{query}/{outputType}";

The method that is invoked is as follows:

public string SearchIndex(string domain, string luceneQuery, OutputType outputType) {
        if (string.IsNullOrEmpty(domain))
            throw new ArgumentNullException(nameof(domain));
        else if (string.IsNullOrEmpty(luceneQuery))
            throw new ArgumentNullException(nameof(luceneQuery));

        var byteArray = Convert.FromBase64String(luceneQuery);
        luceneQuery = Encoding.UTF8.GetString(byteArray);

        return ExecuteCommand("search", outputType == OutputType.Json ? "-json" : "", "--default", domain, luceneQuery);
    }

The method is implemented from an interface:

[OperationContract]
    [WebGet(UriTemplate = Routing.SearchRoute, BodyStyle = WebMessageBodyStyle.Bare)]
    string SearchIndex(string domain, string luceneQuery, OutputType outputType);

And this the output I get from the application in my web browser:

<Code>
    <Value xmlns:a="http://schemas.microsoft.com/ws/2005/05/addressing/none">a:InternalServiceFault</Value>
</Code>
<Reason>
    <Text xml:lang="en-US">Value cannot be null. Parameter name: luceneQuery</Text>
</Reason>
<Detail>
    <ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <HelpLink i:nil="true"/>
        <InnerException i:nil="true"/>
        <Message>Value cannot be null. Parameter name: luceneQuery</Message>
        <StackTrace>
            at De.Nwt.MailArchive.RestService.RestService.SearchIndex (System.String domain, System.String luceneQuery, De.Nwt.MailArchive.RestService.OutputType outputType) [0x00027] in /Users/simoncahill/Projects/MailArchive/RestService/Src/Classes/RestService.cs:104 at (wrapper managed-to-native)                 System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /private/tmp/source-mono-4.6.0/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/corlib/System.Reflection/MonoMethod.cs:305
        </StackTrace>
        <Type>System.ArgumentNullException</Type>
    </ExceptionDetail>
</Detail>

Thanks in advance for any help you can provide me with.

1 Answer 1

1

It seems that your route and your method signature do not match. Your route defines query but your method signature has a luceneQuery parameter. Try changing your method to:

public string SearchIndex(string domain, string query, OutputType outputType)
Sign up to request clarification or add additional context in comments.

3 Comments

Cheers for the hint, I'll give it a try.
Sadly, that did not help. I'm getting the same error, just with the changed parameter name.
In fact, I take that back.I didn't rename the parameter in the interface; after doing that, it works like a charm.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.