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

WCF服务C#调用另一个WCF服务VB,c#,asp.net,vb.net,wcf,C#,Asp.net,Vb.net,Wcf,通常,我不得不接受一个项目来进行改进,而以前的开发人员已经不在公司了。 我在C#中有一个WCF服务,它在VB中调用另一个WCF服务。C#项目对VB WCF服务有一个“服务引用” 它目前在prod中工作,但我并不真正理解它是如何工作的。 在C#服务中,我们使用DTO,输入方法类似于Toto(classDTO1 class1,classDTO2 class2),而VB端类似于Toto(classType1 class1,classType2 class2) C#我有: [ServiceContrac

通常,我不得不接受一个项目来进行改进,而以前的开发人员已经不在公司了。 我在C#中有一个WCF服务,它在VB中调用另一个WCF服务。C#项目对VB WCF服务有一个“服务引用”

它目前在prod中工作,但我并不真正理解它是如何工作的。 在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
_
公共接口IWcfServiceVB
函数Toto(ByVal class1作为类类型1,ByVal class2作为类类型2)作为responseType
端接口
公共类WcfServiceVB实现IWcfServiceVB
公共函数Toto(class1作为classType1,Devision作为DevisionType)作为EligibiliteAugut实现ILBPNoriaWcfService.EligibiliteAug
...
作为响应类型的暗淡响应
...
端函数
末级
部分公共类classType1
公共属性Prop1()作为字符串
...
端属性
末级
部分公共类classType2
公共属性Prop1()作为字符串
...
端属性
末级
公共类响应类型
公共财产以日期时间为基准
作为字符串的公共属性消息
末级
所以,我不明白他是如何无忧无虑地将我的DTO转换成Type的。 如果我通过Visual Studio更新“服务引用”(例如指向prod中现有的VB服务),它会修改我的Reference.cs文件(以及其他内容),解决方案将不再编译。他不能再像以前那样将DTO转换为类型

问题是现在我必须添加一个新的方法VB端,它将被一个新的方法C#端调用。 如果我自动更新引用,它将不再工作,如果我手动修改reference.cs文件以添加新方法,它将编译,但在运行时收到错误消息:

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

描述:不适用于当前产品的例外情况 网络行为的执行。控制桩的跟踪 再加上信息和原始代码

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

我完全被这条消息缠住了。
关于如何使其工作有什么想法吗?)

最后我找到了解决方案,我的一个属性在我的C#服务中是可空的,而在我的VB服务中是不可空的。现在仍然有点不清楚.net如何反序列化我的DTO类以生成一个TypeClass,但至少它现在可以工作了


为了找到问题,我在我的web.config的服务行为中添加了跟踪(),如果它可以帮助某人。

也许你需要将其添加为web服务。如果你已经将VS更新为eg 2015,你需要在som shady options中,而不是VS 2012中,只需在下拉列表中选择它