最好的重载方法有无效的参数

时间:2015-10-13 05:20:47

标签: c# asp.net wcf

Configuration我添加了一个名为ServiceReference2的服务引用

在wcf serrvice中,我在下面有这些代码。

IShowDetails

namespace WcfService1
{

    [ServiceContract]
    public interface IShowDetails
    {
        [OperationContract]
        List<UserDetails> DisplayDetails(UserDetails User);

    }
}

ShowDetails

namespace WcfService1
{
    public class ShowDetails:IShowDetails
    {
        SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString);
        public List<UserDetails> DisplayDetails(UserDetails User)
        {
            //Code
            return result;
        }
    }

}

我使用此wcf服务引用来托管Web应用程序。在Web.Config中添加了

<endpoint address="http://localhost:8426/WcfService1/ShowDetails.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IShowDetails"
    contract="ServiceReference2.IShowDetails" name="BasicHttpBinding_IShowDetails" />

现在在我的一个aspx.cs页面中,我有这些代码。

ServiceReference2.ShowDetailsClient objDisplayUser = new ServiceReference2.ShowDetailsClient();
  protected void Page_Load(object sender, EventArgs e)
    {
        UserDetails User = new UserDetails();
        List<UserDetails> result = objDisplayUser.DisplayDetails(User);

    }

当我为ShowDetailsClient(元数据)执行F12(转到定义)时,我得到这些行

namespace ServiceReference2
{
    [GeneratedCode("System.ServiceModel", "4.0.0.0")]
    [DebuggerStepThrough]
    public class ShowDetailsClient : ClientBase<IShowDetails>, IShowDetails
    {
        public ShowDetailsClient();
        public ShowDetailsClient(string endpointConfigurationName);
        public ShowDetailsClient(Binding binding, EndpointAddress remoteAddress);
        public ShowDetailsClient(string endpointConfigurationName, EndpointAddress remoteAddress);
        public ShowDetailsClient(string endpointConfigurationName, string remoteAddress);

        public UserDetails[] DisplayDetails(UserDetails User);
    }
}

所以在我的aspx.cs页面中我收到错误

最佳重载方法包含无效参数。

我看到公开列表显示详细信息(UserDetails用户)公共UserDetails [] DisplayDetails(UserDetails用户); 看起来不同。如何克服这个?

1 个答案:

答案 0 :(得分:0)

Add Service Reference

添加服务参考时,您是否点击了高级 - &gt;选择了System.Collections.Generic.List并显示在下图中。