c#-WCF-客户端端点配置错误
作者:互联网
在我的客户端应用程序中,出现以下错误:
Could not find endpoint element with name 'QueuedService' and contract
'IMyService' 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 name could be found in the client element.
我使用svutil.exe生成了我正在使用的客户端代理.通常,我手动滚动自己的代理,然后注意到服务合同的接口的生成版本不在我最初在服务合同中指定的名称空间中:
// Auto-generated proxy
namespace MyServices.Contracts
{
// Request object in correct namespace
[System.Runtime.Serialization.DataContractAttribute(
Name="MyRequest",
Namespace="http://schemas.datacontract.org/2004/07/MyServices.Contracts")]
public class MyRequest
{
// ...
}
}
// Service contract NOT in namespace
[System.ServiceModel.ServiceContractAttribute(
ConfigurationName="IMyService")]
public interface IMyService
{
// ...
}
我的主机应用程序web.config指定了服务端点(一个用于MSMQ,一个用于TCP):
<system.serviceModel>
<service>
<!-- etc... -->
<endpoint name="QueuedService"
address="net.msmq://localhost/private/MyQueue"
binding="netMsmqBinding"
bindingConfiguration="MsmqDefaultBinding_Local"
contract="MyService.Contracts.IMyService" />
<endpoint name="TcpService"
address="net.tcp://localhost/ServiceHost/TheService.svc"
contract="MyServices.Contracts.IMyService"
binding="netTcpBinding"
bindingConfiguration="netTcpWindowsBinding" />
</service>
</system.serviceModel>
客户端应用正在使用以下服务:
var endpointConfigName = GetEndpointConfigNameFromConfig();
using(var myServiceClient = new MyServiceClient(endpointConfigName))
{
// Create Request object...
// Call service like so:
myServiceClient.SomeServiceMethod(requestObject);
}
和客户端的web.config:
<client>
<endpoint name="QueuedService"
address="net.msmq://localhost/private/MyQueue"
binding="netMsmqBinding"
bindingConfiguration="MsmqDefaultBinding_Local"
contract="MyServices.Contracts.IMyService" />
<endpoint name="TcpService"
address="net.tcp://localhost/ServiceHost/TheService.svc"
contract="MyServices.Contracts.IMyService"
binding="netTcpBinding"
bindingConfiguration="netTcpWindowsBinding" />
</client>
有任何想法吗???
解决方法:
似乎在Generated proxy中的ConfigurationName只是IMyService,而不是MyServices.Contracts.IMyService.因此,在您的客户端web.config中,您可以只将合同作为IMyService而不是完整的合同进行测试吗?
标签:wcf-client,wcf-binding,wcf,c,net 来源: https://codeday.me/bug/20191101/1986564.html