简体   繁体   English

为什么WCF服务会创建自己的类型?

[英]Why does WCF service create its own type?

In my WCF project, I have a type that comes from a different library: 在我的WCF项目中,我有一个来自不同库的类型:

LibraryB.SomeClass

In the svc.cs file for the service, I use the above type in a parameter: 在该服务的svc.cs文件中,我在参数中使用以上类型:

GetEmployees(LibraryB.SomeClass someClass)

In the web app that is hosting the service, a type is created for the service: 在托管服务的Web应用程序中,将为服务创建一个类型:

MyWebApp.ServiceAReference.ServiceAClient serviceClient = new MyWebApp.ServiceAReference.ServiceAClient();

But when I reference the method: 但是当我引用该方法时:

serviceClient.GetEmployees(someClass);

The intellisense for the parameter is of type: 该参数的智能感知类型为:

MyWebApp.ServiceA.SomeClass

In the web app, someClass is of type LibraryB.SomeClass and not MyWebApp.ServiceA.SomeClass. 在Web应用程序中,someClass的类型为LibraryB.SomeClass,而不是MyWebApp.ServiceA.SomeClass。

Is there some way to tell the web service to send the type LibraryB.SomeClass across the wire? 有没有办法告诉Web服务通过电线发送类型LibraryB.SomeClass? Or is there something different I should be doing? 还是我应该做些不同的事情?

The client does not always have access to the server's types. 客户端并不总是有权访问服务器的类型。 The server might not even be your code! 该服务器甚至可能不是您的代码! For that reason proxy objects are created on the client side to represent the server's objects. 因此,在客户端创建了代理对象来代表服务器的对象。

If the server and client side share the asemblies that contain the type that is sent over the wire, you can tell your application to re-use it when you add your service reference. 如果服务器和客户端共享包含通过有线发送的类型的程序集,则可以在添加服务引用时告诉您的应用程序重新使用它。

添加服务参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM