我有一个有效的 webmethod,并且我添加了一些可选参数(因为我不想让所有调用者负担这些值;它们主要是为了满足我的开发需求,因为我的 webmethod 构造了一个诊断 EventLog.WriteEntry):
[WebMethod(Description = "DownloadFile method for ASP.Net clients")]
public void DownloadFileCF(string trimURL, string TrimRecordNumber
, string CallerPC = "not specified"
, string RequestorID = "not specified")
我也可以使用这样的 RESTful URI 调用上述方法: http://localhost/sdkTrimFileServiceASMX/FileService.asmx/DownloadFileCF?trimURL=60~GROUPER~1137&TrimRecordNumber=5
但后来我明白了:
System.InvalidOperationException: Missing parameter: CallerPC.
at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection)
at System.Web.Services.Protocols.UrlParameterReader.Read(HttpRequest request)
at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
然而,当我在 localhost 上测试 web 服务的 web 方法并仅提供前 2 个文本框的值并单击 INVOKE 按钮时,参数被视为可选。
我对 REST 规则非常陌生。有人可以解决这个问题吗?