我不确定如何解决这个问题,
我想使用WCF为我的用户添加唯一标识符,当我向我的客户端添加GUID时,它会抛出此错误
错误2
参数1:无法从'System.Guid'转换为 'ServiceFairy.client'C:\ Users \ John \ Documents \ Visual Studio 2010 \ Projects \ PremLeague \ ServiceFairy \ Service1.svc.cs
你有什么机会可以帮忙吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data.SqlClient;
using System.Diagnostics;
namespace ServiceFairy
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IService1
{
public List<match> GetAllMatches()
{
matchtableDataContext context = new matchtableDataContext();
var matches = from m in context.matches orderby m.Date select m;
return matches.Take(100).ToList();
}
public List<premtable> GetTable()
{
premContext context = new premContext();
var table = from user in context.premtables orderby user.ID select user;
return table.Take(100).ToList();
}
public Dictionary<Guid, Uri> _clientUris = new Dictionary<Guid, Uri>();
public void Subscribe(Guid clientID, string uri)
{
ClientsDBDataContext context = new ClientsDBDataContext();
context.clients.Insert(clientID);
}
答案 0 :(得分:2)
问题出在您的Subscribe方法的这一行:
context.clients.Insert(clientID); // error: clientID is the wrong type
您将GUID类型的clientID
传递给Insert(),而您应该传递ServiceFairy.client
类型的对象。
看起来你应该创建一个新的client
对象并保存它:
var client = new ServiceFairy.client() { ClientID = clientID }; // TODO: set other properties
context.clients.Insert(client);
正如TODO所示,您也应该设置其他client
属性。
答案 1 :(得分:2)
错误如下:
错误2
参数1:无法从'System.Guid'转换为 'ServiceFairy.client'C:\ Users \ John \ Documents \ Visual Studio 2010 \ Projects \ PremLeague \ ServiceFairy \ Service1.svc.cs 36 44 ServiceFairy
读到这个,我们有:
因此,解决方案是自己弄清楚如何获得'ServiceFairy.client'对象。