簡體   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