简体   繁体   English

WCF服务C#调用另一个WCF服务VB

[英]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#中有一个WCF服务,在VB中调用了另一个WCF服务。 C# project has a "Service Reference" to the VB WCF Service. C#项目具有VB WCF服务的“服务参考”。

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#服务中,我们使用DTO,输入方法类似于Toto(classDTO1 class1,classDTO2 class2),而VB方面类似于Toto(classType1 class1,classType2 class2)。

C# side I have: C#方面,我有:

[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 : 和VB端:

<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. 因此,我不明白他是如何毫无疑问地将我的DTO转换为Type的。 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. 如果我通过Visual Studio更新“服务参考”(例如,指向产品中的现有VB服务),它将修改我的Reference.cs文件(除其他外),并且解决方案不再编译。 He can no longer convert the DTO to Type as before. 他不能再像以前那样将DTO转换为Type。

The concern is that now I have to add a new method VB side, which will be called by a new method C # side. 令人担心的是,现在我必须添加一个新的方法VB端,它将由一个新的方法C#端调用。 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: 如果我自动更新引用,它将无法正常工作;如果我手动修改Reference.cs文件以添加新方法,则可以编译该引用,但在运行时会收到错误消息:

Unexpected error, check with your administrator. 意外错误,请与管理员联系。 Provide the incident number if any.(incident number bfbb876f-98ae-4b29-a405-11fdfe82c872 提供事件编号(如果有)。(事件编号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. Description(说明):按需执行的网络产品除外。 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. 详细信息:System.ServiceModel.FaultException:意外错误,请与管理员联系。 Provide the incident number if any.(incident number bfbb876f-98ae-4b29-a405-11fdfe82c872 提供事件编号(如果有)。(事件编号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. 最后,我找到了解决方案,我的一个属性在我的C#服务中而不是在VB服务中为空。 It stil a bit unclear how .net deserialize my DTO Class to make a TypeClass but at least it work now. 尚不清楚.net如何反序列化我的DTO类以创建TypeClass,但至少现在可以正常工作。

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. 为了找到我在web.config的服务行为中添加的问题,并添加了跟踪( https://docs.microsoft.com/en-us/dotnet/framework/wcf/diagnostics/tracing/configuring-tracing ),它可以帮助某人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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