WCF对象类型 [英] Wcf object types

查看:122
本文介绍了WCF对象类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图具有相同的代码库两个系统之间发送的复杂类型。它们都知道是数据传输介质中的同一对象的。然而,当我通过对消费者的代理对象出现在Web服务的命名空间,而不是一个在应用程序中的对象。

Trying to send a complex type between two systems that have the same code base. They are both aware of the same object that is the data transport medium. However when I pass object on the consumer proxy it appears as an object in the web service namespace instead of the one in the application.

反正是有,我可以定义使用的内部对象?

Is there anyway that I can define to use the internal object?

[WebMethod]
public void Run(TransportObject transport)

出现在我的应用程序下 MyNamespace.Webservice.Transport 而不是 MyNamespace.Objects

appears in my application under MyNamespace.Webservice.Transport instead of MyNamespace.Objects

推荐答案

随着亨克说,在WCF类型的共享是默认的行为。

As Henk says sharing of types in WCF is default behavior.

我将有资格通过扩大它并演示如何实现它:

I will qualify that by expanding on it and demonstrating how to achieve it:

因此​​,而不是有视力。工作室为您生成一个服务引用,你可以有WCF创建代理时,执行由使用的ChannelFactory

So rather than have visual studio generate a service reference for you, you can have WCF create the proxy when it executes by using ChannelFactory.

例如:

// Create service proxy on the fly
var factory = new ChannelFactory<IMyServiceContract>("NameOfMyClientEndpointInConfigFile");
var proxy = factory.CreateChannel();

// Create data contract
var requestDataContract = new MyRequestType();

// Call service operation.
MyResponseType responseDataContract = proxy.MyServiceOperation(requestDataContract);

在上面的例子中, IMyServiceContract 是服务合同和 MyRequestType MyResponseType 是您的数据合同,您可以通过引用组件,其服务也使用引用(其定义了这些类型)。

In the above example, IMyServiceContract is your service contract, and MyRequestType and MyResponseType are your data contracts, which you can use by referencing the assembly which the service also references (which defines these types).

这篇关于WCF对象类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆