我正在尝试创建一个WCF服务并使用jquery AJAX调用其方法.到目前为止,我还没弄清楚如何做到这一点.我已经阅读了SO中给出的一些解决方案,但仍然无法修复它.任何帮助,将不胜感激.我有以下代码.
在WCF服务中.
服务合约
[ServiceContract]
public interface IDatingService
{
[WebInvoke(Method = "POST",
RequestFormat= WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "/AddUser")]
[OperationContract]
User AddUser(User user);
}
Run Code Online (Sandbox Code Playgroud)
履行
public User AddUser(User user)
{
return userRepository.Add(user);
}
Run Code Online (Sandbox Code Playgroud)
配置
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="DatingServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="DatingServiceBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="DatingServiceBehavior"
name="DatingService.Service.DatingService">
<endpoint address="" binding="webHttpBinding"
contract="DatingService.Service.IDatingService"
behaviorConfiguration="DatingServiceBehavior"/>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
从客户端,我使用以下代码来调用该服务.
saveInfo: function () …Run Code Online (Sandbox Code Playgroud) 我正在使用 Aurelia Fetch Client 向 Web API 端点发送文件上传请求。但是 IFormFile 是空的所有磁贴。我的代码如下。
const formData = new FormData();
formData.append("files", account.statement);
const response = await this.http.fetch(url, { method: "POST", body: formData
});
Run Code Online (Sandbox Code Playgroud)
[HttpPost]
public IActionResult Save ()
{
var files = Request.Form.Files;
}
Run Code Online (Sandbox Code Playgroud)
文件始终为空。我已经关注了这篇文章,并按照上面提到的做了。但仍然无法弄清楚什么是错的。