空参数值从HTML表单传递到WCF REST函数

时间:2021-03-21 09:50:04

I have created a RESTful WCF service with a method that will be used to save data using a POST. I want to test this method from an HTML form. The following HTML form and interface definition (and related .cs code) result in the SaveTest function getting called when I hit the form Submit button, however the one argument id is always set to null.

我创建了一个RESTful WCF服务,其中包含一个用于使用POST保存数据的方法。我想从HTML表单中测试此方法。下面的HTML表单和接口定义(以及相关的.cs代码)导致在我点击表单“提交”按钮时调用SaveTest函数,但是一个参数id始终设置为null。

HTML form:

<form action="http://localhost:1378/MyService.svc/SaveTest" method="post">
    <input type="text" id="id"/>
    <input type="submit" value="Submit" />
</form>

Interface definition:

[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "SaveTest")]
Stream SaveTest(string id);

What am I missing here?

我在这里错过了什么?

Edit

Our WCF service has some other methods that use GET that are working without any issues

我们的WCF服务还有一些使用GET的方法,这些方法没有任何问题

i.e. [WebGet(UriTemplate = "GetByTransactionID/{transactionID}")]

即[WebGet(UriTemplate =“GetByTransactionID / {transactionID}”)]

1 个解决方案

#1


There was a similar question on * awhile back. Looks like that poster was successful using a slightly different method.

*上有一个类似的问题。使用略有不同的方法看起来海报成功了。

#1


There was a similar question on * awhile back. Looks like that poster was successful using a slightly different method.

*上有一个类似的问题。使用略有不同的方法看起来海报成功了。