小编Pri*_*era的帖子

从jquery Ajax调用WCF服务

我正在尝试创建一个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)

c# ajax wcf jquery json

5
推荐指数
1
解决办法
2万
查看次数

ASP.NET Core Web API IFormFile 为空,发送 FormData 请求时

我正在使用 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)

Web API 端点

[HttpPost]
public IActionResult Save    ()
{
    var files = Request.Form.Files;
}
Run Code Online (Sandbox Code Playgroud)

文件始终为空。我已经关注了这篇文章,并按照上面提到的做了。但仍然无法弄清楚什么是错的。

multipartform-data fetch-api asp.net-core-webapi iformfile

5
推荐指数
1
解决办法
4334
查看次数