2016-11-16 35 views
0

创建WCF客户端我已经添加服务引用与WSDL文件, 客户抛出错误:编程方式与WsHttpBinding的

Could not find endpoint element with name 'Endpoint1' and contract 'ServiceReference.IService' 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.

我不知道为什么在app.config端点没有回升?

的app.config:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.serviceModel> 
    <bindings> 
     <wsHttpBinding>    
     <binding name="wsHttpPoint"> 
      <security mode="TransportWithMessageCredential"> 
      <transport clientCredentialType="None" /> 
      <message clientCredentialType="UserName" establishSecurityContext="false" /> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="https://example.com:5555/Service.svc" 
     binding="wsHttpBinding" bindingConfiguration="wsHttpPoint" contract="ServiceReference.IService" 
     name="Endpoint1" /> 
    </client> 
    </system.serviceModel> 
</configuration>  

手动创建代理:

WSHttpBinding binding = new WSHttpBinding(); 

binding.Security.Mode = SecurityMode.Transport;    

EndpointAddress address = new EndpointAddress("https://example.com:5555/Service.svc"); 

Client.ClientCredentials.UserName.UserName = "";  
Client.ClientCredentials.UserName.Password = ""; 

Client = new ConnectionServiceClient(binding, address); 

现在有一个新的错误:

connectionSecure channel cannot be opened because security negotiation with the remote endpoint has failed. This may be due to absent or incorrectly specified EndpointIdentity in the EndpointAddress used to create the channel. Please verify the EndpointIdentity specified or implied by the EndpointAddress correctly identifies the remote endpoint.

我是否设置正确的绑定? 每一篇文章我看到有关basichttpBinding的讨论,有没有安全传输的wsHttpbinding例子?

+0

生成的app.config是否与正在执行的程序集不同的项目中? – Marc

+0

它在同一个项目中 – SniperVeera

回答

0

在您的app.config中,客户端需要知道服务器在哪个帐户下运行。只需添加:

<endpoint address="https://example.com:5555/Service.svc" 
    binding="wsHttpBinding" bindingConfiguration="wsHttpPoint" contract="ServiceReference.IService" 
    name="Endpoint1"> 
    <identity> 
     <userPrincipalName value="[email protected]" /> 
    </identity> 
    </endpoint> 

另外,您可能需要将用过的端口注册到执行服务的用户。打开你的开发人员命令提示符以管理员身份并运行:

netsh http add urlacl url=http://+:{Port}/ user={Domain\User} 

交易所在{}价值观您的需求。这只能运行一次。