繁体   English   中英

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

[英]WCF service C# calling another WCF service VB

通常,我必须承担一个项目以进行发展,而以前的开发人员已不在公司中。 我在C#中有一个WCF服务,在VB中调用了另一个WCF服务。 C#项目具有VB WCF服务的“服务参考”。

它目前可以在产品中使用,但我不十分了解。 在C#服务中,我们使用DTO,输入方法类似于Toto(classDTO1 class1,classDTO2 class2),而VB方面类似于Toto(classType1 class1,classType2 class2)。

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

和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

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

令人担心的是,现在我必须添加一个新的方法VB端,它将由一个新的方法C#端调用。 如果我自动更新引用,它将无法正常工作;如果我手动修改Reference.cs文件以添加新方法,则可以编译该引用,但在运行时会收到错误消息:

意外错误,请与管理员联系。 提供事件编号(如果有)。(事件编号bfbb876f-98ae-4b29-a405-11fdfe82c872

Description(说明):按需执行的网络产品除外。 控制堆放的痕迹以及产地代码的附加信息。

详细信息:System.ServiceModel.FaultException:意外错误,请与管理员联系。 提供事件编号(如果有)。(事件编号bfbb876f-98ae-4b29-a405-11fdfe82c872

我完全被这条消息困住了。 有关如何使其工作的任何想法? ;)

最后,我找到了解决方案,我的一个属性在我的C#服务中而不是在VB服务中为空。 尚不清楚.net如何反序列化我的DTO类以创建TypeClass,但至少现在可以正常工作。

为了找到我在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