Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF SQL插入GUID转换错误_C#_.net - Fatal编程技术网

C# WCF SQL插入GUID转换错误

C# WCF SQL插入GUID转换错误,c#,.net,C#,.net,我不知道该怎么办 我想为使用WCF的用户添加唯一标识符,当我向客户端datacontext添加GUID时,它会抛出此错误 错误2 参数1:无法从“System.Guid”转换为 “ServiceFairy.client”C:\Users\John\Documents\Visual Studio 2010\Projects\PremLeague\servicefiry\Service1.svc.cs 你能帮忙吗 using System; using System.Collections.Gene

我不知道该怎么办

我想为使用WCF的用户添加唯一标识符,当我向客户端datacontext添加GUID时,它会抛出此错误

错误2
参数1:无法从“System.Guid”转换为 “ServiceFairy.client”C:\Users\John\Documents\Visual Studio 2010\Projects\PremLeague\servicefiry\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);           
    }       
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Runtime.Serialization;
使用System.ServiceModel;
使用System.ServiceModel.Web;
使用系统文本;
使用System.Data.SqlClient;
使用系统诊断;
命名空间服务精灵
{
//注意:您可以使用“重构”菜单上的“重命名”命令来同时更改代码、svc和配置文件中的类名“Service1”。
公共类服务1:IService1
{
公共列表GetAllMatches()
{
matchtableDataContext上下文=新的matchtableDataContext();
var matches=从上下文中的m开始。matches orderby m。日期选择m;
返回匹配项。Take(100).ToList();
}
公共列表GetTable()
{
premContext=新的premContext();
var table=来自上下文中的用户。premtables orderby user.ID选择用户;
返回表.Take(100.ToList();
}
公共字典_clientUris=新字典();
public void Subscribe(Guid clientID,字符串uri)
{
ClientsDBDataContext=新ClientsDBDataContext();
context.clients.Insert(clientID);
}       

问题在于您在这一行的订阅方法:

context.clients.Insert(clientID);   // error: clientID is the wrong type
您正在将GUID类型的
clientID
传递给Insert(),而应该传递类型为
ServiceFairy.client
的对象

看起来您应该创建一个新的
客户端
对象并保存它:

var client = new ServiceFairy.client() { ClientID = clientID };  // TODO: set other properties
context.clients.Insert(client);

正如TODO所指出的,您还应该设置其他
客户端
属性。

这一行的订阅方法存在问题:

context.clients.Insert(clientID);   // error: clientID is the wrong type
您正在将GUID类型的
clientID
传递给Insert(),而应该传递类型为
ServiceFairy.client
的对象

看起来您应该创建一个新的
客户端
对象并保存它:

var client = new ServiceFairy.client() { ClientID = clientID };  // TODO: set other properties
context.clients.Insert(client);

如TODO所示,您还应该设置其他
客户端属性。

错误如下:

错误2
参数1:无法从“System.Guid”转换为 “ServiceFairy.client”C:\Users\John\Documents\Visual Studio 2010\Projects\PremLeague\servicefiry\Service1.svc.cs 36 44 服务仙女

读到这里,我们有:

  • 参数1有问题。检查所述行的代码,我们可以看到第一个参数是“clientId”
  • “clientId”对象的类型为“System.Guid”
  • 第一个对象的类型必须为“ServiceFairy.client”
  • 系统无法将“system.Guid”神奇地转换为“ServiceFairy.client”

  • 因此,解决方案是自己弄清楚如何获得“ServiceFairy.client”对象。

    错误如下:

    错误2
    参数1:无法从“System.Guid”转换为 “ServiceFairy.client”C:\Users\John\Documents\Visual Studio 2010\Projects\PremLeague\servicefiry\Service1.svc.cs 36 44 服务仙女

    读到这里,我们有:

  • 参数1有问题。检查所述行的代码,我们可以看到第一个参数是“clientId”
  • “clientId”对象的类型为“System.Guid”
  • 第一个对象的类型必须为“ServiceFairy.client”
  • 系统无法将“system.Guid”神奇地转换为“ServiceFairy.client”

  • 因此,解决方案是自己弄清楚如何获得一个“ServiceFairy.client”对象。

    你的问题不清楚为什么你认为这与WCF有关?首先,它只是服务的名称,其次,当我尝试向该表添加GUID时,我创建了一个Linq to SQL对象,其中包含客户端的表抛出该错误,这怎么不清楚?为什么对通常提出问题的人投否决票?这甚至不是Linq或SQL问题。事实上,这与提供的任何标记都不相关-这只不过是提供错误对象类型的简单情况-错误消息清楚地说明了这一点。您的问题不清楚为什么o你认为这与WCF有关吗?首先,这只是服务的名称,其次,我创建了Linq to SQL对象,其中包含客户端的表,当我尝试向该表添加GUID时,它会抛出错误,这怎么不清楚?为什么对通常提出问题的人投反对票?这甚至不是Linq或SQL问题,或者。事实上,这与提供的任何标记都不相关-这只是一个提供错误对象类型的简单案例-错误消息清楚地说明了这一点。感谢Keith的帮助,我真的很感激,我会从现在开始着手,我知道有一个问题我没有传递正确的对象,我的or编辑前的原始问题我想知道如何处理这个问题没有问题John。还要确保你对clientID所做的操作是正确的。它假设Subscribe的调用方想要设置clientID,但通常这些字段是在插入过程中自动生成的。不确定你的设计需要什么。谢谢你的帮助Keith我真的很感激你关于这一点,我将从这一点开始着手,我知道有一个问题我没有传递正确的对象,我在编辑之前的原始问题我想知道如何处理这个问题没有问题John。还要确保你对clientID所做的操作是正确的。它假设Subscribe的调用方想要设置clientID,但是typically这些字段是在插入过程中自动生成的。不确定您的设计需要什么。谢谢,我确实理解了错误,只是我不知道如何操作