0

まず、いくつかのトピックを見つけましたが、私の問題に関連しているとは感じませんでした。

編集:

サービス参照を Silverlight プロジェクトに追加するときに、詳細設定の下にある Reuse types... チェックボックスをオフにしていることを忘れていました。

編集2:わかりました、nvoigtが言ったようにクラスを変更しました。しかし、悲しいことに、これは私の問題を解決しませんでした.私はまだ警告を受けており、まだサービスクライアントを作成していません.

変更されたコードは次のとおりです。

WCF サービスを使用してデータベースを管理する Silverlight プロジェクトがあります。

これが私のカスタム AsyncCallResponse クラスです。

using System;

namespace OnlineButoraruhaz.Web.Response
{
    [DataContract]
    public class AsyncCallResponse
    {
        public AsyncCallResponse()
        {

        }
        public AsyncCallResponse(bool hasSucceeded, Exception error)
        {
            HasSucceeded = hasSucceeded;
            Error = error;
        }
        [DataMember]
        public bool HasSucceeded { get; set; }
        [DataMember]
        public Exception Error { get; set; }
    }
}

AsyncCallResponse から継承する操作コントラクトの戻り値の型にする必要があるカスタム クラスを次に示します。

using System;
using System.Collections.Generic;
using OnlineButoraruhaz.Web.Model;

namespace OnlineButoraruhaz.Web.Response.Furniture
{
    [DataContract]
    public class GetFurnitureListResponse : AsyncCallResponse
    {
        [DataMember]
        public IEnumerable<FurnitureEntityDto> FurnitureList { get; set; }

        public GetFurnitureListResponse()
        {

        }

        public GetFurnitureListResponse(IEnumerable<FurnitureEntityDto> furnitureList, bool hasSucceeded = true, Exception error = null) : base(hasSucceeded, error)
        {
            FurnitureList = furnitureList;
        }
    }
}

ここに私のサービスインターフェースがあります:

using System.ServiceModel;
using OnlineButoraruhaz.Web.Model;
using OnlineButoraruhaz.Web.Response.Furniture;

namespace OnlineButoraruhaz.Web
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IFurnitureService" in both code and config file together.
    [ServiceContract]
    public interface IFurnitureService
    {
        [OperationContract]
        GetFurnitureListResponse GetFurnitureList();

        //the rest of my code...
    }
}

サービスの実装は次のとおりです。

using System;
using System.Data;
using System.Linq;
using OnlineButoraruhaz.Web.Model;
using OnlineButoraruhaz.Web.Response.Furniture;

namespace OnlineButoraruhaz.Web
{

    public class FurnitureService : IFurnitureService
    {
        private readonly FurnitureDataBaseEntities _db = new FurnitureDataBaseEntities();

        public GetFurnitureListResponse GetFurnitureList()
        {
            GetFurnitureListResponse result;

            try
            {
                var query = (from f in _db.FURNITUREs
                             select new FurnitureEntityDto
                             {
                                 FurnitureId = f.FurnitureID,
                                 Name = f.Name,
                                 Type = f.Type,
                                 Color = f.Color,
                                 Width = f.Width,
                                 Height = f.Height,
                                 Depth = f.Depth,
                                 Image = f.Image,
                                 Cover = f.Cover,
                                 Structure = f.Structure,
                                 Price = f.Price,
                                 OnStock = f.OnStock,
                                 RowVersion = f.RowVersion
                             });

                result = new GetFurnitureListResponse(query);
            }
            catch (Exception ex)
            {

                result = new GetFurnitureListResponse(null, false, ex);
            }

            return result;
        }
            //the rest of my code
    }
}

したがって、私の問題は、Silverlight プロジェクトに ServiceReference を追加しようとすると、作成されますが、サービス クライアントの作成に失敗することです。4 つの警告が表示されます。これらは次のとおりです。

Warning 1   Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: ISerializable type with data contract name 'Exception' in namespace 'http://schemas.datacontract.org/2004/07/System' cannot be imported. The data contract namespace cannot be customized for ISerializable types and the generated namespace 'OnlineButoraruhaz.FurnitureServiceReference' does not match the required CLR namespace 'System'. Check if the required namespace has been mapped to a different data contract namespace and consider mapping it explicitly using the namespaces collection. 
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='IFurnitureService']  D:\Workspace\SVN\OnlineFurnitureStore\OnlineButoraruhaz\Service References\FurnitureServiceReference\Reference.svcmap   1   1   OnlineButoraruhaz

Warning 2   Custom tool warning: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
XPath to wsdl:portType: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:portType[@name='IFurnitureService']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='BasicHttpBinding_IFurnitureService']  D:\Workspace\SVN\OnlineFurnitureStore\OnlineButoraruhaz\Service References\FurnitureServiceReference\Reference.svcmap   1   1   OnlineButoraruhaz

Warning 3   Custom tool warning: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:binding[@name='BasicHttpBinding_IFurnitureService']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/']/wsdl:service[@name='FurnitureService']/wsdl:port[@name='BasicHttpBinding_IFurnitureService']  D:\Workspace\SVN\OnlineFurnitureStore\OnlineButoraruhaz\Service References\FurnitureServiceReference\Reference.svcmap   1   1   OnlineButoraruhaz

Warning 4   Custom tool warning: No endpoints compatible with Silverlight 5 were found. The generated client class will not be usable unless endpoint information is provided via the constructor.  D:\Workspace\SVN\OnlineFurnitureStore\OnlineButoraruhaz\Service References\FurnitureServiceReference\Reference.svcmap   1   1   OnlineButoraruhaz

私の主な役割は、サービスによって家具のリストを直接取得するのではなく、家具のリスト、hasSucceeded 論理値、および操作が失敗した場合の例外を含む FurnitureListResponse を取得することです。

誰かが私を助けてくれることを願っています。この問題を抱えているのはちょっと面倒です。解決策についてはわかりません。よろしくお願いします^^

4

1 に答える 1

0

WCF (入力および戻り) によって転送されるすべてのクラスは、DataContractおよび DataMember 属性を正しくシリアル化する必要があります。

使用上のガイドラインについては、こちらをご覧ください。

于 2013-11-01T13:11:54.383 に答える