你如何提供了在Web服务定义为另一个Web服务(股类型)一个类型? [英] How do you supply a type that's defined in a web service to another web service (share types)?

查看:107
本文介绍了你如何提供了在Web服务定义为另一个Web服务(股类型)一个类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2 WCF服务。服务A包含类型myEntity所定义。服务B包含一个服务参考服务A,因此可以使用myEntity所的类型。所以我有一个看起来像这样的方法:

 保护无效更新(ServiceA.MyEntity实体)
{
//做的东西
}

现在我想使用服务A此方法,所以我增加了对服务b的服务引用,并试图:

 保护UpdateServiceB(myEntity所实体)
{
使用(ServiceB.ServiceClient客户端=新ServiceB.ServiceClient())
{
client.Update(实体);
}
}

这没有工作,抱怨类型为不一样的,即使服务b使用的服务A.所定义的类型我该如何解决呢?



更新



我回避这个问题,由于时间限制,并从服务中myEntity所传递的GUID来服务b来代替。然后我用在服务一个名为GetMyEntity(GUID ENTITYID)现有的方法来检索服务B实体:保护

 无效更新(GUID ENTITYID)
{
myEntity所实体=新myEntity所();

使用(ServiceAClient客户端=新ServiceAClient())
{
实体= client.GetMyEntity(ENTITYID);
}

//做的东西
}


解决方案

听起来你正在使用由Visual Studio的添加服务引用命令的方式服务引用。虽然充足,它可以说是在中变得麻烦的大型项目,因为:




  1. 服务类型的重新定义在客户端而不是使用一个公共库(如你已经发现)。


  2. 在服务合同的变化,这通常会导致该服务进行更新,但是,因为点1.客户端代理的客户没有那么变得陈旧加班该模式的发展。你必须为刷新参考




我的建议是最好的不可以使用的添加服务引用并用手滚动您的客户端代理。



执行后,您将有额外的库:




  1. :一种。 Contracts.dll - 在这里你定义所有服务A

  2. 服务接口和数据模型
  3. B.Contracts.dll - 在这里你定义所有的对于服务b

  4. Common.Contracts.dll 服务接口和数据模型 - 如果A和B具有常见的类型,在这里放置它们。 (规范的数据模型)

  5. A.Service.dll - 服务A执行

  6. B.Serivce。 DLL - 服务b实施

  7. ClientProxies.dll - 为所有服务滚你自己的客户端代理



您不必现在就实现上述所有。所需全部是手工的 ClientProxies.dll 并可以随时向迭代其余按要求更高版本。



更多




I've got 2 WCF services. Service A contains the definition of the type MyEntity. Service B contains a service reference to Service A and therefore can use the type for MyEntity. So I have a method that looks like this:

protected void Update (ServiceA.MyEntity entity)
{
    //Do stuff
}

Now I want to use this method in Service A, so I added a service reference for Service B and tried:

protected UpdateServiceB(MyEntity entity)
{
    using(ServiceB.ServiceClient client =  new ServiceB.ServiceClient())
    {
        client.Update(entity);
    }
}

This didn't work and complained that the types were not the same, even though Service B is using the type defined in Service A. How can I solve this?

UPDATE

I avoided the issue due to time constraints and passed the Guid of MyEntity from Service A to Service B instead. I then used an existing method called 'GetMyEntity(Guid entityId)' in Service A to retrieve the entity in Service B:

protected void Update (Guid entityId)
{
    MyEntity entity = new MyEntity();        

    using (ServiceAClient client = new ServiceAClient())
    {
        entity = client.GetMyEntity(entityId);
    }

    //Do stuff
}

解决方案

Sounds like you are using service references by way of Visual Studio's Add Service Reference command. While adequate, it can arguably become troublesome in medium to large projects due to:

  1. Service types are re-defined in the client rather than using a common library (as you have discovered).

  2. When a service contract changes, this will generally cause the service to be updated but not so in the client because of point 1. Client proxies become stale overtime as the schema evolves. You have to refresh reference

My best suggestion is not to use Add Service Reference and roll your client proxies by hand.

Once performed you will have additional libraries:

  1. A.Contracts.dll - here you define all the service interfaces and data models for service A
  2. B.Contracts.dll - here you define all the service interfaces and data models for service B
  3. Common.Contracts.dll - If A & B have common types, place them here. (canonical data models)
  4. A.Service.dll - service A implementation
  5. B.Serivce.dll - service B implementation
  6. ClientProxies.dll - roll-your-own client proxies for all your services

You don't have to implement all of the above now. All that is required is the manual ClientProxies.dll and you can always iterate to the rest later as required.

More

这篇关于你如何提供了在Web服务定义为另一个Web服务(股类型)一个类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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