2016-10-24 36 views
0

因此,我正在编写一个新的WCF服务,当它调用其中一个函数时,它应该返回一个Struct。该结构被保存在共享类中,因为它在程序的其他区域中使用。WCF服务无法从其他类返回结构?

的结构如下所示(请注意,这是一个VB.Net类中,有些项目是在C#):

<DataContract()> 
Public Structure WrapperResults 
    <DataMember()> 
    Dim Success As Boolean 
    <DataMember()> 
    Dim ErrorMessage As String 
End Structure 

现在在WCF服务我已成立我有一个简单测试功能,看起来像这样:

public class TFXEmailProcessor : Wrapper 
    { 
     public MQShared.Functions.WrapperResults CallWrapper(string AppName, string Password, string ConfigXML) 
     { 
      MQShared.Functions.WrapperResults results = new MQShared.Functions.WrapperResults(); 

      results.ErrorMessage = "TFX Test"; 
      results.Success = true; 

      return results; 
     } 
    } 

而在另一个类我已经加入到我的WCF服务,并试图把它的引用,如:

Dim myBinding As New BasicHttpBinding() 
Dim endpointAddress As New EndpointAddress(WP.MyWrapper(x).WrapperURL) 
Dim SR As New WrapperService.WrapperClient(myBinding, endpointAddress) 

Dim WrapResults As MQShared.Functions.WrapperResults = SR.CallWrapper(AppName, Password, WP.MyWrapper(x).ConfigXML) 

然而,SR.CallWrapper函数被Intellisense突出显示,并且我得到了错误Value of type 'FunctionsWrapperResults' cannot be converted to 'Functions.WrapperResults'(注意FunctionsWrapperResults中的缺失时段)

有没有我在这里丢失的东西?

Dim WrapResults = SR.CallWrapper(AppName, Password, WP.MyWrapper(x).ConfigXML) 
+0

试图实现您的Datacontract以上StructLayout。 –

+0

@Nagu_R尝试使用StructLayout.Auto但没有解决问题。 –

+0

我相信,你会创建2套Wrapper结果类,并删除其中的一个/重命名。如果引用的程序集具有相同的程序集标识,则删除或替换其中一个文件引用,以便只有一个文件引用。 –

回答

0

只是让编译器工作了返回值,而不是明确声明为

Dim WrapResults As MQShared.Functions.WrapperResults 

我现在简单地声明函数调用的解决了这个问题调用WCF服务。 代理频道

在Proxy中,您可以使用添加服务引用...通过这种方式,自动生成代理类。你不能使用你的共享类。因为共享类再次作为代理生成。

如果您可以使用共享类,则必须选择通道方式。在通道中,将ServiceContact(接口)和DataContract添加到客户端项目。

我使用C#

var address = new EndpointAddress("..."); // Service address 
    var binding = new BasicHttpBinding(); // Binding type 

    var channel = ChannelFactory<IService>.CreateChannel(binding, address); 

    MQShared.Functions.WrapperResults WrapResults = channel.CallWrapper(string AppName, string Password, string ConfigXML);