【问题标题】:Pass string[] object from client to service wcf将字符串 [] 对象从客户端传递给服务 wcf
【发布时间】:2012-09-12 20:04:56
【问题描述】:

IService1.cs

    [OperationContract]
    string SendMessage(string[] contact, string message,CookieContainer con);

Service1.svc.cs

  string SendMessage(string[] contact, string message,CookieContainer con);
  {
   .... ..... 
   .... 
   ... code
  }

客户端

string[] contact;
svc.SendMessageCompleted += new EventHandler<SendMessageCompletedEventArgs>(svc_Send_Sms);
svc.SendMessageAsync(contact, txtsms.Text,con);

这会报错

'SmsApplication.ServiceReference1.Service1Client.SendMessageAsync(System.Collections.ObjectModel.ObservableCollection, string, System.Net.CookieContainer)' 的最佳重载方法匹配有一些无效参数

参数 1:无法从 'string[]' 转换为 'System.Collections.ObjectModel.ObservableCollection'

【问题讨论】:

    标签: c# wcf windows-phone-7.1


    【解决方案1】:

    我相信这个解决方案应该可行。 右键单击服务参考 选择配置服务参考选项 在 Data Type 部分下,将 Collection 类型从 Array 更改为下拉菜单中所需的类型。

    【讨论】:

    • 我将其更改为 System.Array 并运行应用程序,它会给出类似这样的错误 "格式化程序在尝试反序列化消息时抛出异常:尝试反序列化参数时出错 @987654321 @. InnerException 消息是“第 1 行位置 435 中的错误。不应出现来自命名空间 'tempuri.org' 的 'EndElement''con'。需要元素 'm_count'。'。请参阅 InnerException 以了解“跨度>
    • 我认为您需要将其从 System.Array 更改为 System.Collections.ObjectModel.ObservableCollection
    • 然后它给出了我在问题中提到的 contact 的错误
    • 您是否在代码中的任何位置使用 System.Collections.ObjectModel.ObservableCollection?
    • 我通过 cookiecontainer 对象,即 con
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-17
    • 1970-01-01
    • 1970-01-01
    • 2012-01-07
    • 1970-01-01
    相关资源
    最近更新 更多