如何在C#中调用WCF服务到WCF服务
How to call WCF service to WCF service in C#
我遇到了一个奇怪的问题。
我有一个 WCF 库正在调用一个外部 wcf 服务。我能够在测试客户端中看到预期的结果。
但是我必须在 IIS 中托管这个 WCF 库,为此我必须使用一个 wcf 服务。
我将 Wcflibrary dll 引用到服务中,但在为外部 wcf 服务创建对象时出现以下错误。
An exception of type 'System.InvalidOperationException' occurred in
System.ServiceModel.dll but was not handled in user code
Additional information: Could not find default endpoint element that
references contract 'SMSAgent.SMSGatewayPort' in the ServiceModel
client configuration section. 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.
任何人都可以吗suggest.Is这个场景有什么问题吗?
没有技术原因导致您不能从另一个 WCF 服务调用一个 WCF 服务。您可以将任意数量的服务调用链接在一起。
让我们调用你的调用服务 ServiceA 和外部服务 ServiceB。
您收到的错误是说 ServiceA 中的客户端配置有问题。这意味着告诉 WCF 如何构建从 ServiceA 到 ServiceB 的客户端通道的代码丢失或无效。
现在,对于您要调用的每个服务,您需要在 <system.serviceModel/>
配置中定义一个 endpoint inside the client 部分。您的端点定义必须指定:
- 端点定义的名称
- 您调用的服务地址
- 服务在哪个传输绑定上公开
- 包含服务定义的类型的完全限定名称
或者,您可能需要包含一个 service identity 规范,具体取决于您调用的服务是否需要身份验证。
例如:
<client>
<endpoint name="MyExternalEndpoint"
address="http://externalservice.com"
binding="wsHttpBinding"
contract="ExternalService.IServiceContract" >
<identity>
<dns value="externalservice.com" />
</identity>
</endpoint>
</client>
我遇到了一个奇怪的问题。
我有一个 WCF 库正在调用一个外部 wcf 服务。我能够在测试客户端中看到预期的结果。
但是我必须在 IIS 中托管这个 WCF 库,为此我必须使用一个 wcf 服务。 我将 Wcflibrary dll 引用到服务中,但在为外部 wcf 服务创建对象时出现以下错误。
An exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll but was not handled in user code
Additional information: Could not find default endpoint element that references contract 'SMSAgent.SMSGatewayPort' in the ServiceModel client configuration section. 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.
任何人都可以吗suggest.Is这个场景有什么问题吗?
没有技术原因导致您不能从另一个 WCF 服务调用一个 WCF 服务。您可以将任意数量的服务调用链接在一起。
让我们调用你的调用服务 ServiceA 和外部服务 ServiceB。
您收到的错误是说 ServiceA 中的客户端配置有问题。这意味着告诉 WCF 如何构建从 ServiceA 到 ServiceB 的客户端通道的代码丢失或无效。
现在,对于您要调用的每个服务,您需要在 <system.serviceModel/>
配置中定义一个 endpoint inside the client 部分。您的端点定义必须指定:
- 端点定义的名称
- 您调用的服务地址
- 服务在哪个传输绑定上公开
- 包含服务定义的类型的完全限定名称
或者,您可能需要包含一个 service identity 规范,具体取决于您调用的服务是否需要身份验证。
例如:
<client>
<endpoint name="MyExternalEndpoint"
address="http://externalservice.com"
binding="wsHttpBinding"
contract="ExternalService.IServiceContract" >
<identity>
<dns value="externalservice.com" />
</identity>
</endpoint>
</client>