Asp.net mvc MVC4中使用wcf服务的问题

Asp.net mvc MVC4中使用wcf服务的问题,asp.net-mvc,wcf,asp.net-mvc-4,Asp.net Mvc,Wcf,Asp.net Mvc 4,在我的wcf应用程序IService1.cs中有这样一个类和接口 [ServiceContract] public interface IService1 { [OperationContract] string insertValues(empInfo objInfo); } [DataContract] public class empInfo { string _organizationNam

在我的wcf应用程序IService1.cs中有这样一个类和接口

[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中,我实现了该接口

 public class Service1 : IService1
 {

 public string insertValues(empInfo objInfo)
        {
            .....
        }
 }
然后我创建了一个空的mvc4客户端应用程序来使用这个wcf服务。 我已经添加了ServiceReference,现在它作为ServiceReference1出现在ServiceReference文件夹中 1.创建了名为Defalut1controller的控制器。 2.在这个控制器中,我尝试添加以下行
servicerence1.Service1Client proxy=newservicerence1.Service1Client()
在ActionResult内部。但无法获取ServiceReference1单词

它(ServiceReference1)在我这样更新服务时出现

From-
字符串插入值(empInfo objInfo)-To-
字符串插入值(字符串objInfo)

现在我已经构建了这个wcf应用程序,并在我的客户机mvc4应用程序中更新了服务引用。现在

ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client();
行已启用


我已经尝试使用.net web应用程序来使用相同的功能,我可以毫无问题地使用,mvc4中缺少的功能,请帮助。提前感谢。

问题本身和您面临的问题对我来说有点不清楚,但您是否确实尝试过在您的
empInfo
数据合同中公开任何公共属性?因为现在您只有3个私有字段,它们不会在客户端的代理代码中生成。

多亏了stackoverflow,我得到了答案

这就是解决方案:

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

  • 它对我也起到了作用。

    Microsoft在这次更新中修复了这个问题:

    是的,我拥有公共字符串OrganizationName{get{return}OrganizationName;}set{U OrganizationName=value;}}[DataMember]公共字符串OrganizationAddr等公共属性{get{return{organizationAddr;}set{{organizationAddr=value;}}[DataMember]公共整数?TotalEmployees{get{return}totalemp;}set{U totalemp=value;}多亏了stackoverflow,我得到了答案。这是解决方案:1)右键单击服务引用2)选择配置服务引用3)选择指定引用程序集中的重用类型4)只需选择除“Newtonsoft.json”之外的所有内容即可。@d感谢您的回复。