简体   繁体   中英

WCF service C# calling another WCF service VB

As often, I have to take a project to make an evolution and the previous developer is no longer in the company. I have a WCF service in C# that calls another WCF service in VB. C# project has a "Service Reference" to the VB WCF Service.

It works currently in prod, but I do not really understand how. In the C# service, we use DTO and the input method is like Toto(classDTO1 class1, classDTO2 class2), while VB side is like Toto(classType1 class1, classType2 class2).

C# side I have:

[ServiceContract()]
public interface IWcfService
{
    [XmlSerializerFormat()]
    [OperationContract()]
    responseDTO Toto(classDTO1 class1, classDTO2 class2);
}

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]    
public class WcfService: IWcfService
{
        public reponseDTO Toto(classDTO1 class1, classDTO2 class2)
        {
                ...
                using(WcfServiceVB clientVB = new WcfServiceVB())
                {
                        responseDTO rep = clientVB.Toto(class1, class2);
                        clientVB.Close();
                }
                ...
        }
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.33440")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[XmlTypeAttribute(TypeName = "classType1", Namespace = "http://namespace/")]
public class classDTO1
{
        [XmlElementAttribute(ElementName = "Prop1", IsNullable = true)]
        public string Prop1{ get; set; }
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.33440")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[XmlTypeAttribute(TypeName = "classType2", Namespace = "http://namespace/")]
public class classDTO2
{
        [XmlElementAttribute(ElementName = "Prop1", IsNullable = true)]
        public string Prop1{ get; set; }
}

public class eligibiliteAOGOut
{
    public DateTime CreaDate { get; set; }
    public string Message { get; set; }
}

And VB side :

<ServiceContract()> _
Public Interface IWcfServiceVB

        <XmlSerializerFormat>
        <OperationContract()>
        Function Toto(ByVal class1 As classType1, ByVal class2 As classType2) As responseType

End Interface

Public Class WcfServiceVB Implements IWcfServiceVB

        Public Function Toto(class1 As classType1, devis As devisType) As eligibiliteAOGOut Implements ILBPNoriaWcfService.eligibiliteAOG

                ...
                Dim response as responseType
                ...

        End Function

End Class

<System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.33440"),
System.SerializableAttribute(),
System.Diagnostics.DebuggerStepThroughAttribute(),
System.ComponentModel.DesignerCategoryAttribute("code"),
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://namespace/")>
Partial Public Class classType1

        <System.Xml.Serialization.XmlElementAttribute(IsNullable:=True)>
        Public Property Prop1() As String
                ...
        End Property
End Class

<System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.0.30319.33440"),
System.SerializableAttribute(),
System.Diagnostics.DebuggerStepThroughAttribute(),
System.ComponentModel.DesignerCategoryAttribute("code"),
System.Xml.Serialization.XmlTypeAttribute([Namespace]:="http://namespace/")>
Partial Public Class classType2

        <System.Xml.Serialization.XmlElementAttribute(IsNullable:=True)>
        Public Property Prop1() As String
                ...
        End Property
End Class

Public Class responseType

        Public Property CreaDate As DateTime
        Public Property Message As String

End Class

So, I do not understand how he converted my DTO into Type without worries. If I update the "Service Reference" via Visual Studio (and pointing to the existing VB service in prod for example), it modifies my Reference.cs file (among other things) and the solution no longer compiles. He can no longer convert the DTO to Type as before.

The concern is that now I have to add a new method VB side, which will be called by a new method C # side. If I automatically update the reference, it does not work anymore and if I modify the Reference.cs file by hand to add my new method, it compiles but I get an error message at runtime:

Unexpected error, check with your administrator. Provide the incident number if any.(incident number bfbb876f-98ae-4b29-a405-11fdfe82c872

Description : Une exception non gérée s'est produite au moment de l'exécution de la demande Web actuelle. Contrôlez la trace de la pile pour plus d'informations sur l'erreur et son origine dans le code.

Détails de l'exception: System.ServiceModel.FaultException: Unexpected error, check with your administrator. Provide the incident number if any.(incident number bfbb876f-98ae-4b29-a405-11fdfe82c872

I'm completly stuck with this message. Any ideas on how to make it work ? ;)

Finally I found the solution, one of my property was nullable in my C # service and not in my VB service. It stil a bit unclear how .net deserialize my DTO Class to make a TypeClass but at least it work now.

To find the problem I added in the service behaviors of my web.config and I added traces ( https://docs.microsoft.com/en-us/dotnet/framework/wcf/diagnostics/tracing/configuring-tracing ), if it can help someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM