0

WCF サービスのカスタム オブジェクトを呼び出し元の asp.net アプリケーションに返す必要があります。エラーが発生します Cannot implicitly convert type 'test.ServiceReference1.ReturnClass' to 'test.ReturnClass' here is my calling function in asp.net (error im bold) Can i return my object and how?

// Get the drive list from the client machine
ServiceReference1.JobsClient Client = new ServiceReference1.JobsClient();
Client.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://" + DropDownListSystems.SelectedValue + ":8732/test/");
ReturnClass Drive_Result = new ReturnClass(); // Declare an instance of the return object that will contain all the results
**Drive_Result = Client.FindDrives();**

ここに私のWCFコードがあります

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Collections;
namespace WCFJobsLibrary
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IJobs" in both code and config file together.
    [ServiceContract]
    public interface IJobs
    {
         //Directoy Manager
         [OperationContract]
        ReturnClass FindDrives();
         //Directoy Manager
         [OperationContract]
         ReturnClass FindSubfolders(String Folder_To_Search);
         //Directoy Manager
         [OperationContract]
         ReturnClass FindSubFiles(String Folder_To_Search);


    }
}

//Directoy Manager
public ReturnClass FindDrives()
{

    try
    {
        DriveInfo[] allDrives = DriveInfo.GetDrives();
        ArrayList Drives = new ArrayList();
        foreach (DriveInfo d in allDrives)
        {
            Drives.Add(d.Name);
        }
        return new ReturnClass(1, String.Empty, String.Empty, Drives, null, null);
    }
    catch (Exception ex)
    {
        return new ReturnClass(-1, ex.Message.ToString(), ex.InnerException.ToString(), null, null, null);
    }

}



public class ReturnClass
{
    //private members
    private int _errorCode;
    private string _errorMessage;
    private string _exMessage;
    private ArrayList _drives;
    private string[] _folders;
    private string[] _filePaths;


    #region Constructors

    //constructor 1
    public ReturnClass()
    {

    }

    //constructor 2
    public ReturnClass(int iErr, string sErrMsg, string ExMsg, ArrayList arrDrives, string[] sfolders, string[] sFilePaths)
    {
        ErrorCode = iErr;
        ErrorMessage = sErrMsg;
        ExMessage = ExMsg;
        Drives = arrDrives;
        Folders = sfolders;
        FilePaths = sFilePaths;
    }

    #endregion

    #region methods

    //Error Code
    public int ErrorCode
    {
        get { return this._errorCode; }
        set { this._errorCode = value; }
    }

    //error message
    public string ErrorMessage
    {
        get { return this._errorMessage; }
        set { this._errorMessage = value; }
    }

    //exception message
    public string ExMessage
    {
        get { return this._exMessage; }
        set { this._exMessage = value; }
    }

    //drives
    public ArrayList Drives
    {
        get { return this._drives; }
        set { this._drives = value; }
    }

    //folders
    public string[] Folders
    {
        get { return this._folders; }
        set { this._folders = value; }
    }

    //File Paths
    public string[] FilePaths
    {
        get { return this._filePaths; }
        set { this._filePaths = value; }
    }

    #endregion

}
4

2 に答える 2

0

Drive_Resultas test.ServiceReference1.ReturnClass, notと宣言するだけですReturnClass(名前空間に何か問題があります)。

于 2012-08-17T22:27:28.650 に答える
0

returnClass と datamember に datacontract を設定する必要があります [DataContract] public class ReturnClass { //private members private int _errorCode; プライベート文字列 _errorMessage; プライベート文字列 _exMessage; プライベート ArrayList _drives; プライベート文字列[] _folders; プライベート文字列[] _filePaths;

#region Constructors

//constructor 1
public ReturnClass()
{

}

//constructor 2
public ReturnClass(int iErr, string sErrMsg, string ExMsg, ArrayList arrDrives, string[] sfolders, string[] sFilePaths)
{
    ErrorCode = iErr;
    ErrorMessage = sErrMsg;
    ExMessage = ExMsg;
    Drives = arrDrives;
    Folders = sfolders;
    FilePaths = sFilePaths;
}

#endregion

#region methods

//Error Code
[DataMember]
public int ErrorCode
{
    get { return this._errorCode; }
    set { this._errorCode = value; }
}

//error message
[DataMember]
public string ErrorMessage
{
    get { return this._errorMessage; }
    set { this._errorMessage = value; }
}

//exception message
[DataMember]
public string ExMessage
{
    get { return this._exMessage; }
    set { this._exMessage = value; }
}

//drives
[DataMember]
public ArrayList Drives
{
    get { return this._drives; }
    set { this._drives = value; }
}

//folders
[DataMember]
public string[] Folders
{
    get { return this._folders; }
    set { this._folders = value; }
}

//File Paths
[DataMember]
public string[] FilePaths
{
    get { return this._filePaths; }
    set { this._filePaths = value; }
}

#endregion
于 2012-08-17T22:28:54.770 に答える