如何从C#类调用类型为POST的WCF方法?
WCF方法
[OperationContract]
[WebInvoke(Method = "POST",
UriTemplate = "/process",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped)]
MyRespons Process(MyRequest req);
我怎样才能从aspx代码背后调用它呢?
我试图通过webclient接收流,它可以与任何get方法一起使用,但不能与POST一起使用.该方法适用于Fiddler和POSTER:
string getDeclarations = string.Format("{0}/process", ServiceBaseAddress);
var proxy = new WebClient();
proxy.DownloadStringCompleted += ProxyDownloadDeclarationsCompleted;
proxy.DownloadStringAsync((new Uri(getDeclarations)));
解决方法:
您可以使用jQuery完成此操作.这也是great example供您使用.
这是一个示例代码块.
$.ajax({
cache: false,
type: "POST",
async: false,
url: /* YOUR URL */,
data: JSON.stringify(/* YOUR POST DATA */),
contentType: "application/json",
dataType: "json",
success: function (response) {
/* SUCCESS FUNCTION */
},
error: function (error) {
/* ERROR FUNCTION */
}
});
已编辑
这是使用WebClient执行POST的Stackoverflow示例reference.
标签:wcf,c
来源: https://codeday.me/bug/20191127/2077010.html