简体   繁体   English

从另一个WCF服务调用一个WCF服务:端点错误?

[英]Call one WCF service from another WCF Service: Endpoint Error?

I have a WCF service Service1 that has a service reference to another WCF service Service2. 我有一个WCF服务Service1,该服务具有对另一个WCF服务Service2的服务引用。

Both services are self hosted and can be accessed normally when not referencing one another. 两种服务都是自托管的,并且在不相互引用时可以正常访问。

Inside a method in Service1 I have a call to the other service 在Service1的方法内部,我调用了另一个服务

public String DoWork()
{
    using(Service2Client client = new Service2Client())
    {
         return client.DoWork();
    }
}

The method containing this code is called from another project referencing Service1 like so: 包含该代码的方法是从引用Service1的另一个项目中调用的,如下所示:

using (Service1Client client = new Service1Client())
{
     result = client.DoWork();
}

When this project attempts to consume the service I get an error message: 当该项目尝试使用该服务时,我收到一条错误消息:

System.ServiceModel.FaultException`1: 'Could not find default endpoint element that references contract 'Service2Reference.IService2' in the ServiceModel client configuration section. System.ServiceModel.FaultException`1:'在ServiceModel客户端配置部分中找不到引用合同'Service2Reference.IService2'的默认终结点元素。 This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.' 这可能是因为找不到您的应用程序的配置文件,或者是因为在客户端元素中找不到与该协定匹配的端点元素。

Any ideas on how to fix this? 有想法该怎么解决这个吗? I am fairly inexperienced with WCF. 我对WCF经验不足。

I have read about adding the endpoint but I'm not entirely sure which config file to add it to (eg the client which makes the call or the host of the service which calls another service)? 我已经读过有关添加端点的信息,但是我不确定要将该端点添加到哪个配置文件(例如,进行调用的客户端或调用另一个服务的服务的主机)?

Thanks 谢谢

Add a client tag to the Service1 App.Config file. 将客户端标签添加到Service1 App.Config文件。 The client endpoint that is added to the Service1 App.Config file should match an exposed endpoint that is setup is Service2's App.Config file. 添加到Service1 App.Config文件的客户端端点应与设置为Service2的App.Config文件的公开端点匹配。 The client tag in service one would look like this: 服务一中的客户端标签如下所示:

    <system.serviceModel>
        ....Other Config....
        <client>
            <endpoint address="serviceAddress" binding="bindingType"
             bindingConfiguration="BindingConfig" contract="ContractNamespace"
             name="NameOfEndpoint">
        </client>
     </system.serviceModel>

The binding type needs to match the binding type that is exposed by the hosted service, Service 2 in your example. 绑定类型需要与托管服务(示例中的服务2)公开的绑定类型匹配。 Contract is the Interface that describes the methods that are exposed by the service. 合同是描述服务公开的方法的接口。

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

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