Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.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无法将数据合约分离/封装到自己的cs文件中-堆栈溢出异常_C#_Asp.net_Web Services_Wcf - Fatal编程技术网

C# WCF无法将数据合约分离/封装到自己的cs文件中-堆栈溢出异常

C# WCF无法将数据合约分离/封装到自己的cs文件中-堆栈溢出异常,c#,asp.net,web-services,wcf,C#,Asp.net,Web Services,Wcf,我有一个有趣的问题。每当我尝试将数据契约分离到它们自己的cs文件中时……当在服务方法中使用其中一个数据契约时,由于堆栈溢出异常,我的get进程将终止。似乎我需要将数据契约放在接口类中以解决问题,但是,我希望在wcf服务应用程序的DTO目录下为每个数据契约提供一个单独的cs文件。代码没有问题,只有当我尝试将数据契约移动到它们自己的类中时才会发生错误。了解一下为什么会发生这种情况会很好。wcf测试客户端将在使用这些方法但连接到我的控制台应用程序时生成正确的响应。只有接口cs文件(Iservice.c

我有一个有趣的问题。每当我尝试将数据契约分离到它们自己的cs文件中时……当在服务方法中使用其中一个数据契约时,由于堆栈溢出异常,我的get进程将终止。似乎我需要将数据契约放在接口类中以解决问题,但是,我希望在wcf服务应用程序的DTO目录下为每个数据契约提供一个单独的cs文件。代码没有问题,只有当我尝试将数据契约移动到它们自己的类中时才会发生错误。了解一下为什么会发生这种情况会很好。wcf测试客户端将在使用这些方法但连接到我的控制台应用程序时生成正确的响应。只有接口cs文件(Iservice.cs)中的数据协定可以与方法一起工作,但是,它们自己的cs文件中的数据协定会引发异常

数据协定在其自己的cs文件中

using developer1.Core.Dto.Account;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace developer1.Core.Dto.Account
{
    [DataContract]
    public class AccountDto
    {
        Guid accountId = Guid.NewGuid();
        Guid userId = Guid.NewGuid();
        string accountName = "default";
        string bankName = "default";


        [DataMember]
        public Guid AccountId
        {
            get { return accountId; }
            set { accountId = value; }
        }


        [DataMember]
        public Guid UserId
        {
            get { return userId; }
            set { userId = value; }
        }
        [DataMember]
        public string AccountName
        {
            get { return accountName; }
            set { accountName = value; }
        }

        [DataMember]
        public string BankName
        {
            get { return bankName; }
            set { bankName = value; }
        }



    }
}
方法消耗对象

public AccountDto createAccount(string accountName, string bankName)
{
    AccountDto newAccount = new AccountDto() { AccountName = accountName, BankName = bankName };
    return newAccount;
}
副班

using developer1.Core.Dto.Account;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
//using AccountDto = developer1.Core.Dto.Account.AccountDto;

namespace developer1.Core.ServiceContracts
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IService1
    {

        [OperationContract]
        string GetData(int value);

        [OperationContract]
        CompositeType GetDataUsingDataContract(CompositeType composite);

        [OperationContract]
        CompositeType createComposite(string value);

        [OperationContract]
        List<AccountDto> GenerateMultipleAccounts(int count);
        // TODO: Add your service operations here
        [OperationContract]
        AccountDto createAccount(string accountName, string bankName);

        [OperationContract]
        AccountDto2 createAccount2(string stringValue, bool boolValue);
    }


    // Use a data contract as illustrated in the sample below to add composite types to service operations.
    [DataContract]
    public class CompositeType
    {
        bool boolValue = true;
        string stringValue = "Hello ";

        [DataMember]
        public bool BoolValue
        {
            get { return boolValue; }
            set { boolValue = value; }
        }

        [DataMember]
        public string StringValue
        {
            get { return stringValue; }
            set { stringValue = value; }
        }
    }

    public class AccountDto2
    {
        bool boolValue = true;
        string stringValue = "Hello ";

        [DataMember]
        public bool BoolValue
        {
            get { return boolValue; }
            set { boolValue = value; }
        }

        [DataMember]
        public string StringValue
        {
            get { return stringValue; }
            set { stringValue = value; }
        }


    }


}
使用developer1.Core.Dto.Account;
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用System.Runtime.Serialization;
使用System.ServiceModel;
使用System.ServiceModel.Web;
使用系统文本;
//使用AccountDto=developer1.Core.Dto.Account.AccountDto;
命名空间developer1.Core.ServiceContracts
{
//注意:您可以使用“重构”菜单上的“重命名”命令同时更改代码和配置文件中的接口名称“IService1”。
[服务合同]
公共接口IService1
{
[经营合同]
字符串GetData(int值);
[经营合同]
CompositeType GetDataUsingDataContract(CompositeType composite);
[经营合同]
CompositeType createComposite(字符串值);
[经营合同]
列出GenerateMultipleAccounts(整数计数);
//TODO:在此处添加服务操作
[经营合同]
AccountdToCreateCount(字符串accountName,字符串bankName);
[经营合同]
AccountDto2 createAccount2(字符串stringValue,布尔布尔值);
}
//如下面的示例所示,使用数据协定将复合类型添加到服务操作中。
[数据合同]
公共类复合类型
{
布尔布尔值=真;
string stringValue=“Hello”;
[数据成员]
公共布尔布尔值
{
获取{返回布尔值;}
设置{boolValue=value;}
}
[数据成员]
公共字符串字符串值
{
获取{return stringValue;}
设置{stringValue=value;}
}
}
公共类AccountDto2
{
布尔布尔值=真;
string stringValue=“Hello”;
[数据成员]
公共布尔布尔值
{
获取{返回布尔值;}
设置{boolValue=value;}
}
[数据成员]
公共字符串字符串值
{
获取{return stringValue;}
设置{stringValue=value;}
}
}
}

同样,接口类中的任何数据约定都会导致方法正常工作。但是他们自己的cs文件中的任何契约都会因堆栈溢出异常而破坏方法

,所以我解决了这个可怕的问题。您必须创建WCF服务库,而不是WCF服务应用程序。我的天哪,应用程序不会让你在界面外拆分组件,这太愚蠢了。所以我解决了这个可怕的问题。您必须创建WCF服务库,而不是WCF服务应用程序。我的天哪,应用程序不会让你在界面之外拆分组件,这太愚蠢了。