使用WCF服务时出错

时间:2012-09-06 10:35:40

标签: c# .net wcf

我正在尝试从客户端应用程序中使用wcf服务。 WCF服务托管在Web中。 将服务引用添加到项目后,将生成所有代理。

当我尝试访问代理类方法时,我收到以下错误:

无法加载合同“XService.XServicePortType”的端点配置部分,因为找到了该合同的多个端点配置。请按名称指明首选端点配置部分。

在app.config中,我删除了自定义绑定端点。我只有一个http终点。

<system.serviceModel>
  <bindings>
    <basicHttpBinding> xxxxxxx </basicHttpBinding>
  </bindings>
  <client>
    <endpoint address="x" 
              binding="basicHttpBinding" 
              bindingConfiguration="xServiceSoap11Binding" 
              contract="xServicePortType" 
              name="xHttpSoap11Endpoint" />
    <endpoint address="y" 
              binding="basicHttpBinding" 
              bindingConfiguration="ySoap11Binding" 
              contract="yServicePortType" 
              name="yHttpSoap11Endpoint" />
  </client>
</system.serviceModel>

在线失败:

XServicePortTypeClient buService = new XServicePortTypeClient();

XServicePortType的代码是自动生成的。

<endpoint name="xServiceHttpSoap11Endpoint1" contract="xService.xServicePortType" bindingType="basicHttpBinding" address="http://zz:8086/RABSAPI2BUService/services/xService.xServiceHttpSoap11Endpoint/" bindingConfiguration="xServiceSoap11Binding1">
  <properties>
    <property path="/address" isComplexType="false" isExplicitlyDefined="true" clrType="System.Uri, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue>http://zz:8086/RABSAPI2BUService/services/xService.xServiceHttpSoap11Endpoint/</serializedValue>
    </property>
    <property path="/behaviorConfiguration" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue />
    </property>
    <property path="/binding" isComplexType="false" isExplicitlyDefined="true" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue>basicHttpBinding</serializedValue>
    </property>
    <property path="/bindingConfiguration" isComplexType="false" isExplicitlyDefined="true" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue>xServiceSoap11Binding1</serializedValue>
    </property>
    <property path="/contract" isComplexType="false" isExplicitlyDefined="true" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue>xService.xServicePortType</serializedValue>
    </property>
    <property path="/headers" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.AddressHeaderCollectionElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue>System.ServiceModel.Configuration.AddressHeaderCollectionElement</serializedValue>
    </property>
    <property path="/headers/headers" isComplexType="false" isExplicitlyDefined="true" clrType="System.ServiceModel.Channels.AddressHeaderCollection, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue>&lt;Header /&gt;</serializedValue>
    </property>
    <property path="/identity" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.IdentityElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue>System.ServiceModel.Configuration.IdentityElement</serializedValue>
    </property>
    <property path="/identity/userPrincipalName" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.UserPrincipalNameElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue>System.ServiceModel.Configuration.UserPrincipalNameElement</serializedValue>
    </property>
    <property path="/identity/userPrincipalName/value" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue />
    </property>
    <property path="/identity/servicePrincipalName" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.ServicePrincipalNameElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue>System.ServiceModel.Configuration.ServicePrincipalNameElement</serializedValue>
    </property>
    <property path="/identity/servicePrincipalName/value" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue />
    </property>
    <property path="/identity/dns" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.DnsElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue>System.ServiceModel.Configuration.DnsElement</serializedValue>
    </property>
    <property path="/identity/dns/value" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue />
    </property>
    <property path="/identity/rsa" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.RsaElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue>System.ServiceModel.Configuration.RsaElement</serializedValue>
    </property>
    <property path="/identity/rsa/value" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue />
    </property>
    <property path="/identity/certificate" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.CertificateElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue>System.ServiceModel.Configuration.CertificateElement</serializedValue>
    </property>
    <property path="/identity/certificate/encodedValue" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue />
    </property>
    <property path="/identity/certificateReference" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.CertificateReferenceElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue>System.ServiceModel.Configuration.CertificateReferenceElement</serializedValue>
    </property>
    <property path="/identity/certificateReference/storeName" isComplexType="false" isExplicitlyDefined="false" clrType="System.Security.Cryptography.X509Certificates.StoreName, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue>My</serializedValue>
    </property>
    <property path="/identity/certificateReference/storeLocation" isComplexType="false" isExplicitlyDefined="false" clrType="System.Security.Cryptography.X509Certificates.StoreLocation, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue>LocalMachine</serializedValue>
    </property>
    <property path="/identity/certificateReference/x509FindType" isComplexType="false" isExplicitlyDefined="false" clrType="System.Security.Cryptography.X509Certificates.X509FindType, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue>FindBySubjectDistinguishedName</serializedValue>
    </property>
    <property path="/identity/certificateReference/findValue" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue />
    </property>
    <property path="/identity/certificateReference/isChainIncluded" isComplexType="false" isExplicitlyDefined="false" clrType="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue>False</serializedValue>
    </property>
    <property path="/name" isComplexType="false" isExplicitlyDefined="true" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue>xServiceHttpSoap11Endpoint1</serializedValue>
    </property>
    <property path="/kind" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue />
    </property>
    <property path="/endpointConfiguration" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <serializedValue />
    </property>
  </properties>
</endpoint>

@Mike C:XServicePortType的代码是自动生成的。

 <endpoint name="xServiceHttpSoap11Endpoint1" contract="xService.xServicePortType" bindingType="basicHttpBinding" address="http://zz:8086/RABSAPI2BUService/services/xService.xServiceHttpSoap11Endpoint/" bindingConfiguration="xServiceSoap11Binding1">
      <properties>
        <property path="/address" isComplexType="false" isExplicitlyDefined="true" clrType="System.Uri, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue>http://zz:8086/RABSAPI2BUService/services/xService.xServiceHttpSoap11Endpoint/</serializedValue>
        </property>
        <property path="/behaviorConfiguration" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue />
        </property>
        <property path="/binding" isComplexType="false" isExplicitlyDefined="true" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue>basicHttpBinding</serializedValue>
        </property>
        <property path="/bindingConfiguration" isComplexType="false" isExplicitlyDefined="true" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue>xServiceSoap11Binding1</serializedValue>
        </property>
        <property path="/contract" isComplexType="false" isExplicitlyDefined="true" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue>xService.xServicePortType</serializedValue>
        </property>
        <property path="/headers" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.AddressHeaderCollectionElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue>System.ServiceModel.Configuration.AddressHeaderCollectionElement</serializedValue>
        </property>
        <property path="/headers/headers" isComplexType="false" isExplicitlyDefined="true" clrType="System.ServiceModel.Channels.AddressHeaderCollection, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue>&lt;Header /&gt;</serializedValue>
        </property>
        <property path="/identity" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.IdentityElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue>System.ServiceModel.Configuration.IdentityElement</serializedValue>
        </property>
        <property path="/identity/userPrincipalName" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.UserPrincipalNameElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue>System.ServiceModel.Configuration.UserPrincipalNameElement</serializedValue>
        </property>
        <property path="/identity/userPrincipalName/value" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue />
        </property>
        <property path="/identity/servicePrincipalName" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.ServicePrincipalNameElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue>System.ServiceModel.Configuration.ServicePrincipalNameElement</serializedValue>
        </property>
        <property path="/identity/servicePrincipalName/value" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue />
        </property>
        <property path="/identity/dns" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.DnsElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue>System.ServiceModel.Configuration.DnsElement</serializedValue>
        </property>
        <property path="/identity/dns/value" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue />
        </property>
        <property path="/identity/rsa" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.RsaElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue>System.ServiceModel.Configuration.RsaElement</serializedValue>
        </property>
        <property path="/identity/rsa/value" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue />
        </property>
        <property path="/identity/certificate" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.CertificateElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue>System.ServiceModel.Configuration.CertificateElement</serializedValue>
        </property>
        <property path="/identity/certificate/encodedValue" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue />
        </property>
        <property path="/identity/certificateReference" isComplexType="true" isExplicitlyDefined="false" clrType="System.ServiceModel.Configuration.CertificateReferenceElement, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue>System.ServiceModel.Configuration.CertificateReferenceElement</serializedValue>
        </property>
        <property path="/identity/certificateReference/storeName" isComplexType="false" isExplicitlyDefined="false" clrType="System.Security.Cryptography.X509Certificates.StoreName, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue>My</serializedValue>
        </property>
        <property path="/identity/certificateReference/storeLocation" isComplexType="false" isExplicitlyDefined="false" clrType="System.Security.Cryptography.X509Certificates.StoreLocation, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue>LocalMachine</serializedValue>
        </property>
        <property path="/identity/certificateReference/x509FindType" isComplexType="false" isExplicitlyDefined="false" clrType="System.Security.Cryptography.X509Certificates.X509FindType, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue>FindBySubjectDistinguishedName</serializedValue>
        </property>
        <property path="/identity/certificateReference/findValue" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue />
        </property>
        <property path="/identity/certificateReference/isChainIncluded" isComplexType="false" isExplicitlyDefined="false" clrType="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue>False</serializedValue>
        </property>
        <property path="/name" isComplexType="false" isExplicitlyDefined="true" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue>xServiceHttpSoap11Endpoint1</serializedValue>
        </property>
        <property path="/kind" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue />
        </property>
        <property path="/endpointConfiguration" isComplexType="false" isExplicitlyDefined="false" clrType="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <serializedValue />
        </property>
      </properties>
    </endpoint>

1 个答案:

答案 0 :(得分:1)

  

合同的端点配置部分   无法加载“XService.XServicePortType”,因为多个   找到该合同的端点配置。转载请注明   首选端点配置部分。

在装订中包含装配合同名称和合同。此外,XML区分大小写,因此 xServicePortType XServicePortType 不同。

<system.serviceModel>
  <bindings>
    <basicHttpBinding> xxxxxxx </basicHttpBinding>
  </bindings>
  <client>
    <endpoint address="x" 
              binding="basicHttpBinding" 
              bindingConfiguration="xServiceSoap11Binding" 
              contract="XService.XServicePortType" 
              name="xHttpSoap11Endpoint" />
    <endpoint address="y" 
              binding="basicHttpBinding" 
              bindingConfiguration="ySoap11Binding" 
              contract="YService.YServicePortType" 
              name="yHttpSoap11Endpoint" />
  </client>
</system.serviceModel>