none
Problems with Generating Client Service Proxy in VS 2005 RRS feed

  • Question

  • In my ServiceClass I have two typed FaultExceptions (see code below). When I try to generate a Service Reference in VS 2005 (-> Add Service Reference), the generator makes some weird code (multiple defintions for some properties etc.). Does anybody knows what the problem is? As soon as I comment the <FaultContract> Attribute, everything works fine again.

    Thanx

    ******************************

    Imports System
    Imports System.ServiceModel
    Imports System.Runtime.Serialization
    Imports Microsoft.Practices.EnterpriseLibrary.Data

    <ServiceContract()> _
    Public Interface ICiresService
        <OperationContract()> _
        Function MyOperation1(ByVal myValue As String) As String

        <OperationContract()> _
        Function MyOperation2(ByVal dataContractValue1 As Kunde) As String

        <OperationContract()> _
        Function GetProducts() As List(Of String)


        <FaultContract(GetType(DatabaseFault))> _
        <FaultContract(GetType(ConfigFault))> _
        <OperationContract()> _
        Function GetPersonsAsDataSet() As DataSet


    End Interface

    Public Class CiresService
        Implements ICiresService


        Public Function MyOperation1(ByVal myValue As String) As String Implements ICiresService.MyOperation1
            Return "Hello: " + myValue
        End Function

        Public Function MyOperation2(ByVal dataContractValue1 As Kunde) As String Implements ICiresService.MyOperation2
            Return "Hello: " + dataContractValue1.FirstName
        End Function

        Public Function GetProducts() As System.Collections.Generic.List(Of String) Implements ICiresService.GetProducts

            Dim list As New List(Of String)
            Dim db As Database = Nothing
            Dim dr As IDataReader

            Try
                db = DatabaseFactory.CreateDatabase("AW_DB")
            Catch ex As Exception
                Dim cf As ConfigFault = New ConfigFault()
                cf.ConfigOperation = "Create Database"
                cf.ConfigReason = "Exception reading configuration"
                cf.ConfigMessage = ex.Message
                Throw New FaultException(Of ConfigFault)(cf)
                'Throw New FaultException("Test", New FaultCode("Test"))
            End Try

            Try
                dr = db.ExecuteReader(CommandType.Text, "SELECT ProductNumber FROM Production.Product")
            Catch ex As Exception
                Dim df As DatabaseFault = New DatabaseFault()
                df.DBOperation = "ExecuteReader"
                df.DBReason = "Exception querying database"
                df.DBMessage = ex.Message
                Throw New FaultException(Of DatabaseFault)(df)
                'Throw New FaultException("Test", New FaultCode("Test"))
            End Try


            Try
                While dr.Read()
                    list.Add(dr.GetString(0))
                End While
            Catch ex As Exception
                Throw New FaultException("Exception when filling the list object", New FaultCode("List.Add"))
            End Try

            Return List
        End Function

        Public Function GetPersonsAsDataSet() As System.Data.DataSet Implements ICiresService.GetPersonsAsDataSet
            Dim db As Database = DatabaseFactory.CreateDatabase("AW_DB")

            Return db.ExecuteDataSet(CommandType.Text, "SELECT TOP 20 ContactID, FirstName, LastName FROM Person.Contact WHERE LastName LIKE N'A%'")
        End Function
    End Class

    <DataContract()> _
    Public Class Kunde
        Private m_firstName As String
        Private m_lastName As String

        <DataMember()> _
        Public Property FirstName() As String
            Get
                Return m_firstName
            End Get
            Set(ByVal value As String)
                m_firstName = value
            End Set
        End Property

        <DataMember()> _
        Public Property LastName() As String
            Get
                Return m_lastName
            End Get
            Set(ByVal value As String)
                m_lastName = value
            End Set
        End Property
    End Class

    <DataContract()> _
    Public Class ConfigFault

        Dim _ConfigOperation As String

        <DataMember()> _
        Public Property ConfigOperation() As String
            Get
                Return _ConfigOperation
            End Get
            Set(ByVal value As String)
                _ConfigOperation = value
            End Set
        End Property


        Dim _ConfigReason As String

        <DataMember()> _
        Public Property ConfigReason() As String
            Get
                Return _ConfigReason
            End Get
            Set(ByVal value As String)
                _ConfigReason = value
            End Set
        End Property

        Dim _ConfigMessage As String

        <DataMember()> _
        Public Property ConfigMessage() As String
            Get
                Return _ConfigMessage
            End Get
            Set(ByVal value As String)
                _ConfigMessage = value
            End Set
        End Property

    End Class

    <DataContract()> _
    Public Class DatabaseFault
        Dim _DBOperation As String

        <DataMember()> _
        Public Property DBOperation() As String
            Get
                Return _DBOperation
            End Get
            Set(ByVal value As String)
                _DBOperation = value
            End Set
        End Property


        Dim _DBReason As String

        <DataMember()> _
        Public Property DBReason() As String
            Get
                Return _DBReason
            End Get
            Set(ByVal value As String)
                _DBReason = value
            End Set
        End Property

        Dim _DBMessage As String

        <DataMember()> _
        Public Property DBMessage() As String
            Get
                Return _DBMessage
            End Get
            Set(ByVal value As String)
                _DBMessage = value
            End Set
        End Property

    End Class


    Friday, May 18, 2007 9:13 AM

Answers

  • It seems that we are generating 2 partial classes with the same members. I will take this issue to the team responsible for metadata importing and report back, but in the meantime I recommend that you simply delete the extraneous generated class (Kunde).

    Wednesday, May 23, 2007 3:31 PM

All replies

  • It seems that we are generating 2 partial classes with the same members. I will take this issue to the team responsible for metadata importing and report back, but in the meantime I recommend that you simply delete the extraneous generated class (Kunde).

    Wednesday, May 23, 2007 3:31 PM
  • Repro!!!

     

    We are suffering the same issue. This is a stopper one.

     

    I can reproduce this bug with the following simple sevice contract and data contract, that i have developed as simplest case. It is imposible get a proxy working for that case either using VS2005, SvcUtil or VS 'Orcas'.

     

    I think that this bug deserves a hotfix as soon as posible.

     

    [DataContract]

    public class PagedResult

    {

    [DataMember]

    public DataSet Data;

    }

     

    [ServiceContract]

    public interface IWorkplaceService

    {

    [FaultContract(typeof(string))]

    [OperationContract]

    void Foo(PagedResult p);

    }

     

    [ServiceBehavior]

    public class WorkplaceService : IWorkplaceService

    {

    public void Foo(PagedResult p)

    {

    }

    }

    Friday, May 25, 2007 11:40 AM
  • Repro too,

     

    It's a really annoying bug, my friend...

     

    My code looks as follows:

     

    [ServiceContract( Name = "WorkplaceService", Namespace = "http://www.sisteplant.com/captor/v3")]

    public interface IWorkplaceService

    {

    [OperationContract]

    [FaultContract(typeof(CaptorServerFault))]

    int Search(ArrayList parameters, out DataSet result);

    }

    -------------------

     

    [DataContract(Namespace = "http://www.sisteplant.com/captor/v3")]

    public class CaptorServerFault

    {

    string _faultCode;

    [DataMember]

    public string FaultCode

    {

    get { return _faultCode; }

    set { _faultCode = value; }

    }

    public CaptorServerFault(string faultCode)

    {

    FaultCode = faultCode;

    }

    }

    -------------------

     

    This code produces duplicated code on proxies. It works fine if:

    • We use a simple class as FaultContract (for example, a string instead of CaptorServerFault)
    • We supress any of the parameters (DataSet or ArrayList). Both of them must be present in order to fail.

     

    It also reproduces if:

    • We change the ArrayList with an object array
    • We change the ArrayList with a ICollection<object>
    • ... etc
    Friday, May 25, 2007 12:02 PM
  • Something similar happens to me.

    If a specifiy an Exception as FaultType, as [FaultContract(typeof(SecurityException))], I loose the clients (both interface and inplementation) from VS generated code.

    A fix (quickly) is required? You have news about that?
    Sunday, July 29, 2007 11:40 PM