English 中文(简体)
如何在代理类中正确指定复杂类型?
原标题:How to properly specify a complex type in the proxy class?
  • 时间:2012-05-23 09:47:13
  •  标签:
  • c#
  • wcf

我在服务器上有一个“强”服务合同

[ServiceContract]
public interface ICheckService
{
    [OperationContract]
    IEnumerable<Message> CheckInbox(string user);
}

我将上述定义复制为客户端的 < 坚固> 代理等级 < /坚固 > :

[ServiceContract]
public interface ICheckService
{
    [OperationContract]
    IEnumerable<Message> CheckInbox(string user);
}

当我正在编辑客户时, 我得到以下错误 :

The type or namespace name  Message  could not be found (are you missing a using directive or an assembly reference?) (CS0246)

电文.cs

public class Message
{
    public int message_id;
    public string message_from;
    public string message_to;
    public string message_text;
    public DateTime message_time;
}

Datacontracts 是在这里起作用的吗? 如果是的话,我在服务合同的定义中应该修改什么?

注:服务合同还有其他业务合同,这些合同返回简单的数据类型并正在运作。

最佳回答
[DataContract]
public class Message{
[DataMember]
public String Sender{get;set;}
//etc - not sure what your message class contains
}

类似的东西:)

问题回答

请注意, WCF 是一个信息通信框架,这些电文是 Dataparties ,换句话说,它们是由 Datacontract 属性命名的类别,以便告知 WCF ,该类的该对象会通过服务进行通信或旅行。在您的示例中,您正在向客户发送一系列对象,而此 class 应该是 Datacontracts ,而客户认为其可见的属性应该由 Data meman 属性来标注。

 [DataContract]
 public class Message
 {
   [DataMember]
   public string Name{get;set;}
 }

因此,您应当修改您的合同Message ,而不是服务合同。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签