asp.net-mvc - 在 mvc 4 中使用 wcf 服务的问题

标签 asp.net-mvc wcf asp.net-mvc-4

我的 wcf 应用程序 IService1.cs 中有这样的类和接口(interface)

[ServiceContract]
    public interface IService1
    {
        [OperationContract]
        string insertValues(empInfo objInfo);
    }

    [DataContract]
    public class empInfo
    {
        string _organizationName = string.Empty;
        string _organizationAddr = string.Empty;
        int? _totalemp;
    }

在 Service1.svc.cs 中,我已经实现了该接口(interface)。
 public class Service1 : IService1
 {

 public string insertValues(empInfo objInfo)
        {
            .....
        }
 }

然后我创建了一个空的 mvc4 客户端应用程序来使用这个 wcf 服务。
我已经添加了 ServiceReference,现在它作为 ServiceReference1 出现在服务引用文件夹中。然后我这样做了
1. 创建了一个名为 Defalut1controller 的 Controller 。
2.在这个 Controller 中,我尝试添加以下行
ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client();在 ActionResult 中。但无法获取 ServiceReference1 字。

当我像这样更新我的服务时出现它的(ServiceReference1)

来自 - string insertValues(empInfo objInfo); - 至 - string insertValues(string objInfo);
现在我已经构建了这个 wcf 应用程序,并在我的客户端 mvc4 应用程序中更新了服务引用。现在
ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client();

行已启用。

我已经尝试使用 .net Web 应用程序来使用相同的内容,我可以毫无问题地做,我错过了 mvc4,请帮忙。提前致谢..

最佳答案

感谢stackoverflow,我得到了答案。

这是解决方案:

  • 右键单击服务引用
  • 选择配置服务引用
  • 在指定的引用程序集中选择重用类型
  • 只需选择除“Newtonsoft.json”之外的所有内容

  • 它也对我有用。

    关于asp.net-mvc - 在 mvc 4 中使用 wcf 服务的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16435229/

    相关文章:

    c# - WebMatrix WebSecurity 密码盐

    c# - 如何将 Html.Password 帮助器的值传递给 Action

    asp.net-mvc - 为什么在 asp.net mvc 中的公共(public)路由之前先映射特殊路由?

    json - 如何使用 AngularJS 为双向绑定(bind)制作格式过滤器

    c# - 聊天 - 获取新消息可用性的最佳方式

    asp.net-mvc - 如何在 App_Code 文件夹中的 Razor View 中使用 Url.Action

    javascript - Ajax jquery 发送 Null 值到 Mvc4 Controller

    c# - IHttpClientFactory 单例 .NET 框架

    asp.net-mvc - 在MVC中使用领域模型和 View 模型(也称为AutoMapper)的设计模式名称是什么

    asp.net - iisreset之后无法启动应用程序池