简体   繁体   English

WCF DataContact和代理WCF服务。

[英]WCF DataContact and Proxy WCF Service.

I have two WCF services one on a Master server (Managed by a third party, don't have much access there) and another on my local server, basically the reason for the local service to exist is to store data locally in case the Master service is offline (for any reason) and then upload the data back whenever Master service becomes available. 我有两个WCF服务,一个在主服务器上(由第三方管理,在那里没有太多访问权限),另一个在我的本地服务器上,基本上,存在本地服务的原因是在万一主服务器上本地存储数据服务处于脱机状态(出于任何原因),然后在主服务可用时将数据上传回去。

To keep the client application transparent of where to hit with the data (Master service/local service) I am making the local service as proxy. 为了使客户端应用程序对数据的访问位置(主服务/本地服务)透明,我将本地服务作为代理。 ie, the client application would only call local service and then it in turns checks the health of the Master server to get/post data, in case it is offline it uses local cache, and pushes data back to server whenever available. 也就是说,客户端应用程序将仅调用本地服务,然后依次检查主服务器的运行状况以获取/发布数据,以防它处于脱机状态,它使用本地缓存,并在可用时将数据推送回服务器。

Now there are some complex DataContract in the master service (and they are loads of them), and I since don't have access to actual data contract attributed files (it is managed by a third party), and since any added reference (SOAP) creates complex types locally, but with XML Serialization attributes instead of DataMembers/DataContracts I won't be able to reuse the types as is or can I? 现在,主服务中有一些复杂的DataContract(它们是它们的负载),而且由于我无法访问实际的数据合同属性文件(由第三方管理),而且由于我添加了任何引用(SOAP) )在本地创建复杂的类型,但是使用XML序列化属性而不是DataMembers / DataContracts创建属性,我将无法原样重用这些类型,还是可以?

Is there a way around or do I just have to either get through the 3rd Party or create my contracts? 有没有解决的办法,还是我只需要通过第三方参加或创建合同?

I have some queries :- 我有一些疑问:-

  1. Well what do you mean by managed by third party? 那么,由第三方管理意味着什么? Is it a separate Organization providing/maintaining the WCF service and you don't have the code? 它是提供/维护WCF服务的单独组织,您没有代码吗?

  2. Is you're local service kind of wrapper? 您是本地服务类的包装人员吗?

If you by any means get hold of Data Contracts and Service contract that would be the best as you're local service can implement the same Service Contract using the same Data Contracts. 如果您以任何方式获得了数据合同和服务合同,那将是最好的选择,因为您所在的本地服务可以使用相同的数据合同来实施相同的服务合同。 Along with that you can have one more Service Contract which you can use to push data back when the master service is up. 除此之外,您还可以拥有一个服务合同,可以在主服务启动时将数据推回。

Refer to the Example below :- 请参考以下示例:

public interface IMasterService
{
    TResponse PersistData(TRequestObject request);
}

public interface ILocalService
{
    TResponse PushDataInBatch(TRequestObject[] requestBatch);

    //We can add more methods here if required
}

public MasterService : IMasterService
{
    public TResponse PersistData(TRequestObject request) 
    {
        //persist data in Master DB
    }
}

public LocalService : IMasterService, ILocalService
{
    public TResponse PersistData(TRequestObject request) 
    {
        //persist data in local cache
    }

    public TResponse PushDataInBatch(TRequestObject[] requestBatch) 
    {
        //persist data in local cache
    }
}

Let me know if the above thoughts helped you, feel free to give more information and then we can check it in detail. 如果上述想法对您有所帮助,请随时提供更多信息,然后我们可以对其进行详细检查。


Above implementation could have been the approach if you have access to their libraries, however if you don't then you are only left with one option to take a service reference of the MasterService and persist the data accordinlgly. 如果您可以访问它们的库,则可以采用上述实现方法,但是,如果您没有访问它们的库,则只剩下一个选择以获取MasterService的服务引用并一致地保留数据。

One more query, in your LocalService am assuming you are duplicating the persisting logic (in local datastore)? 再一个查询,在您的LocalService中是否假设您正在复制持久性逻辑(在本地数据存储区中)?

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

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