0

First of all, I have found several topics, but I've not felt any of them relevant to my problem.

Edit:

I forgot to say, when I am adding the Service Reference to the Silverlight project, I am unticking Reuse types... checkbox under advanced settings.

Edit 2: Ok, now I modified my classes like nvoigt said. But sadly this didn't solve my problem, I am still getting the warnings, and still not creating the service client.

Here is the modified code:

I have a Silverlight project that uses a WCF service to manage database.

Here is my custom AsyncCallResponse class:

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; }
    }
}

Here is my custom class that should be my return type of the operation contract inheriting from the 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;
        }
    }
}

Here is my Service interface:

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...
    }
}

Here is the implementation of the service:

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
    }
}

So, my problem, is when I am trying to add ServiceReference in my Silverlight project, it creates, but fails to create the service client. I get 4 warnings, here are them:

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

My main role is to not directly get the Furniture's list by the service, but get a FurnitureListResponse which contains the furniture's list, a hasSucceeded logical value, and an exception, if the operation fails.

I hope anyone can help me, it's kindda annoying having this problem, and I have no idea about the solution. Thanks in advance ^^

4

1 回答 1

0

WCF 传输的所有类(输入和返回)都需要正确序列化DataContract和 DataMember 属性。

在这里查看使用指南。

于 2013-11-01T13:11:54.383 回答