具有同等命名端点的多个服务

时间:2014-01-08 13:16:38

标签: c# visual-studio-2010 web-services wsdl endpoint

我只是创建一些小型C#程序来访问第三方Web服务。有不同的服务,但结构非常相似 - 特别是在绑定的命名约定

服务的WSDL'QueryCustomerIn'

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:tns="http://sap.com/xi/A1S/Global" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" ...>
...
  <wsdl:binding name="binding_SOAP12" type="tns:QueryCustomerIn">
    ...
  </wsdl:binding>
  <wsdl:service name="service">
    <wsdl:port name="binding_SOAP12" binding="tns:binding_SOAP12">
      <wsoap12:address location="https://my123456.sapbydesign.com/sap/bc/srt/scs/sap/querycustomerin1?sap-vhost=my123456.sapbydesign.com"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

'QueryOrganisationalCentreIn'

的WSDL
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:tns="http://sap.com/xi/A1S/Global" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" ...>
...
  <wsdl:binding name="binding_SOAP12" type="tns:QueryOrganisationalCentreIn">
    ...
  </wsdl:binding>
  <wsdl:service name="service">
    <wsdl:port name="binding_SOAP12" binding="tns:binding_SOAP12">
      <wsoap12:address location="https://my123456.sapbydesign.com/sap/bc/srt/scs/sap/queryorganisationalcentrein?sap-vhost=my123456.sapbydesign.com"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

如您所见,两个服务都将其端点命名为“binding_SOAP12”,但每个服务都指向不同的位置。

当我使用“添加服务引用”在Visual Studio 2010中创建客户端时,我可以通过以下方式访问该服务:

QueryOrganisationalCentreInClient client = new QueryOrganisationalCentreInClient("binding_SOAP12");

但是当我添加第二个服务时,第二个服务的类似请求

QueryCustomerInClient client = new QueryCustomerInClient("binding_SOAP12");

因System.InvalidOperationException失败(无法找到端点或者endpointcontract无效)。

我测试了一些东西,发现了以下内容:

  • 第一个客户端(组织...)仍然像添加第二个服务之前一样正常工作
  • 如果我创建一个新项目并且只是以相同的方式添加第二个服务(Customer ...)(但没有任何其他服务)它可以工作。
  • 当我为Customer ... Service编辑(提供的)WSDL文件并将端点名称更改为其他名称时,它也可以与第一个服务一起在项目中工作(Organizational ...)< / LI>

看起来VisualStudio 2010无法处理同一项目中不同服务合同中同名的端点。但由于我无法决定端点的命名:尽管存在这个问题,我怎样才能在项目中使用这两种服务?

提前致谢,
弗兰克

2 个答案:

答案 0 :(得分:1)

向导只是一种生成代码和配置的方法。如果您不喜欢它(因为它不起作用),只需进入项目的app.config并手动重命名一个绑定定义。

答案 1 :(得分:1)

您的代码可能存在两个不同的问题。

你能展示你的.config吗?

您有时会获得1 binding name和2 endpoint addresses相同的contract。一个用于1.1肥皂,另一个用于1.2。你应该尝试删除其中一个。

在其他情况下,您可以拥有1个绑定名称和2个端点,但只有在合同类不同时才有效。