0
私はアプリケーション用にREST APIを構築しています。これまでのところ、基本は機能します。 サービスに接続すると、コマンドが呼び出されます。 しかし、私のメソッドの1つには、(string)luceneQueryというパラメータがあります。メソッドのパラメータをどこに置いても、URLパラメータに入力するものに関係なく、常にnullまたは空です。C#REST API、URLパラメータがnullです
私は正直なところこのことを理解することはできません。私は数時間それを行っています。 Googleでさえ私を怒らせている。ここ
は、私が使用している経路である:
public const string SearchRoute = "/search/{domain}/{query}/{outputType}";
次のように呼び出されるメソッドである。
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);
}
方法は、インタフェースから実装されている:
[OperationContract]
[WebGet(UriTemplate = Routing.SearchRoute, BodyStyle = WebMessageBodyStyle.Bare)]
string SearchIndex(string domain, string luceneQuery, OutputType outputType);
これはWebブラウザのアプリケーションから出力されます:
<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>
ご協力いただきありがとうございます。
ヒントのために乾杯してみてください。 – SimonC
悲しいことに、それは役に立たなかった。変更されたパラメータ名と同じエラーが表示されます。 – SimonC
実際には、私はそれを取り戻します。私はインターフェイスのパラメータの名前を変更しませんでした。それをした後、それは魅力のように動作します。 – SimonC