2014-09-02 49 views
0

我是通过2程序回复,直到当前的消息完成处理

第一(WCF服务)的web.config

<?xml version="1.0"?> 
<configuration> 

    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.serviceModel> 

     <behaviors> 
      <serviceBehaviors> 
       <behavior name ="svcbh"> 

        <serviceDiscovery> 
        <announcementEndpoints> 
         <endpoint kind="udpAnnouncementEndpoint"></endpoint> 
        </announcementEndpoints> 
        </serviceDiscovery> 

        <serviceMetadata httpGetEnabled="False"/> 
        <serviceDebug includeExceptionDetailInFaults="False"/> 

       </behavior> 
      </serviceBehaviors> 
     </behaviors> 

     <!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />--> 

     <services> 
      <service name ="WCF.Service.Service1" behaviorConfiguration ="svcbh" > 
       <host> 
        <baseAddresses> 
         <add baseAddress = "http://localhost:9000/Service1/" /> 
        </baseAddresses> 
       </host> 
       <endpoint name ="duplexendpoint" 
          address ="" 
          binding ="wsDualHttpBinding" 
          contract ="WCF.Service.IService1"/> 
       <endpoint name ="MetaDataTcpEndpoint" 
          address="mex" 
          binding="mexHttpBinding" 
          contract="IMetadataExchange"/> 
      </service> 
     </services> 

    </system.serviceModel> 
<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 

</configuration> 

和我的客户项目(应用程序创建一个WCF服务项目的.config)

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <wsDualHttpBinding> 
       <binding name="SecureBinding"> 
        <security mode="Message"> 
         <message clientCredentialType="Windows" /> 
        </security> 
       </binding> 
       <binding name="duplexendpoint" closeTimeout="00:01:00" openTimeout="00:01:00" 
        receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" 
        transactionFlow="false" maxBufferPoolSize="524288" maxReceivedMessageSize="1073741824" 
        messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" /> 
       <binding name="duplexendpoint1" /> 
      </wsDualHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="http://92.168.1.199:9000/Service1/" binding="wsDualHttpBinding" 
       bindingConfiguration="duplexendpoint" contract="ServiceReference1.IService1" 
       name="duplexendpoint"> 
       <identity> 
        <userPrincipalName value="[email protected]" /> 
       </identity> 
      </endpoint> 
      <endpoint address="http://localhost:9000/Service1/" binding="wsDualHttpBinding" 
       bindingConfiguration="duplexendpoint1" contract="ServiceReference1.IService1" 
       name="duplexendpoint1"> 
       <identity> 
        <userPrincipalName value="MyName" /> 
       </identity> 
      </endpoint> 
     </client> 

    </system.serviceModel> 
<appSettings> 

<add key="connectionstring" value="Provider=SQLOLEDB.1;Password=a;Persist Security Info=True;User ID=sa;Initial Catalog=Serita;Data Source=.;" /> 

</appSettings> 
</configuration> 

我运行它成功ñ本地运行 但我遇到了域名,我讨厌梅托德proxy.open();开放代理 代码

public partial class HQMSSyncForm : Form, IService1Callback 
    { 
     Service1Client proxy; 
     public HQMSSyncForm() 
     { 
      InitializeComponent(); 
     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 
      try 
      { 
       InstanceContext context = new InstanceContext(this); 
       proxy = new Service1Client(context); 
       proxy.Open(); // Error this Line 
       proxy.RegisterClient(); 
       ClinicService.Instance.SetConnectionString(ConfigurationSettings.AppSettings["connectionstring"]); 
      } 
      catch (Exception ex) 
      { 
       MessageBox.Show("Error in HQMS is : " + ex.Message); 
      } 
     } 

回答

0

我解决我的问题 当你看到这个错误安装

The caller was not authenticated by the service. 

检查Windows身份验证或没有在Windows Server(用于安装Feuture - >添加Feuture - >点net xxx - > WCF服务)

先安装它 后在客户端 如果用户在域服务器有密码注释这行在app.config

<identity> 
        <userPrincipalName value="MyName" /> 
       </identity> 

所以,befor开放的代理添加此行

proxy.ClientCredentials.Windows.ClientCredential.Password = "password"; 
     proxy.ClientCredentials.Windows.ClientCredential.UserName = "Username"; 
     proxy.ClientCredentials.Windows.ClientCredential.Domain = "DomainName"; 

成功:-)