0

我有一个 ServiceLibrary Application(Host) - LTService,它是我的应用程序的起点。它的合约接受三个参数用户名、密码和 xmlstring。在验证它之后,我正在验证和反序列化 xmlstring。现在我在同一个解决方案中有另一个 ServiceLibrary Application(Host) - WCFServiceDialler。它接受用户名、密码和我从上面反序列化 xml 的过程中获得的对象。

我让我的客户在另一个 Web 应用程序 prj 中使用 DiallerService - partnercontract 我在其中添加服务引用,它可以找到 WCFServiceDialler 公开的合同。但是当我运行以下代码时:

> LeadTransfer.PartnerContracts.DiallerServiceReference.DiallerClient
> client = new
> LeadTransfer.PartnerContracts.DiallerServiceReference.DiallerClient("wsHttpBinding");
>         WCFServiceDialler.DiallerData diallerData = new WCFServiceDialler.DiallerData();
>         diallerData.Username = "xxxx";
>         diallerData.Password = "xxx";
>         DiallerServiceReference.CarLeadDO temp = new DiallerServiceReference.CarLeadDO();
>         diallerData.carLeadDO = (DiallerServiceReference.CarLeadDO)Convert.ChangeType(tempDataMediator,
> typeof(DiallerServiceReference.CarLeadDO));
>         client.DiallerProcess(diallerData);

第一条语句引发异常

在 ServiceModel 客户端配置部分中找不到名称为“wsHttpBinding”和合同“DiallerServiceReference.IDialler”的端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此名称匹配的端点元素。

我无法弄清楚它无法找到端点。我的启动应用程序都是上面的 WCF 服务项目。

以下是我的客户端服务应用程序中的 wsdl 定义:

    <?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://tempuri.org/" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Service" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsp:Policy wsu:Id="WSHttpBinding_IDialler_policy">
    <wsp:ExactlyOne>
      <wsp:All>
        <sp:SymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
          <wsp:Policy>
            <sp:ProtectionToken>
              <wsp:Policy>
                <sp:SecureConversationToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
                  <wsp:Policy>
                    <sp:RequireDerivedKeys />
                    <sp:BootstrapPolicy>
                      <wsp:Policy>
                        <sp:SignedParts>
                          <sp:Body />
                          <sp:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing" />
                          <sp:Header Name="From" Namespace="http://www.w3.org/2005/08/addressing" />
                          <sp:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing" />
                          <sp:Header Name="ReplyTo" Namespace="http://www.w3.org/2005/08/addressing" />
                          <sp:Header Name="MessageID" Namespace="http://www.w3.org/2005/08/addressing" />
                          <sp:Header Name="RelatesTo" Namespace="http://www.w3.org/2005/08/addressing" />
                          <sp:Header Name="Action" Namespace="http://www.w3.org/2005/08/addressing" />
                        </sp:SignedParts>
                        <sp:EncryptedParts>
                          <sp:Body />
                        </sp:EncryptedParts>
                        <sp:SymmetricBinding>
                          <wsp:Policy>
                            <sp:ProtectionToken>
                              <wsp:Policy>
                                <sp:SpnegoContextToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
                                  <wsp:Policy>
                                    <sp:RequireDerivedKeys />
                                  </wsp:Policy>
                                </sp:SpnegoContextToken>
                              </wsp:Policy>
                            </sp:ProtectionToken>
                            <sp:AlgorithmSuite>
                              <wsp:Policy>
                                <sp:Basic256 />
                              </wsp:Policy>
                            </sp:AlgorithmSuite>
                            <sp:Layout>
                              <wsp:Policy>
                                <sp:Strict />
                              </wsp:Policy>
                            </sp:Layout>
                            <sp:IncludeTimestamp />
                            <sp:EncryptSignature />
                            <sp:OnlySignEntireHeadersAndBody />
                          </wsp:Policy>
                        </sp:SymmetricBinding>
                        <sp:Wss11>
                          <wsp:Policy />
                        </sp:Wss11>
                        <sp:Trust10>
                          <wsp:Policy>
                            <sp:MustSupportIssuedTokens />
                            <sp:RequireClientEntropy />
                            <sp:RequireServerEntropy />
                          </wsp:Policy>
                        </sp:Trust10>
                      </wsp:Policy>
                    </sp:BootstrapPolicy>
                  </wsp:Policy>
                </sp:SecureConversationToken>
              </wsp:Policy>
            </sp:ProtectionToken>
            <sp:AlgorithmSuite>
              <wsp:Policy>
                <sp:Basic256 />
              </wsp:Policy>
            </sp:AlgorithmSuite>
            <sp:Layout>
              <wsp:Policy>
                <sp:Strict />
              </wsp:Policy>
            </sp:Layout>
            <sp:IncludeTimestamp />
            <sp:EncryptSignature />
            <sp:OnlySignEntireHeadersAndBody />
          </wsp:Policy>
        </sp:SymmetricBinding>
        <sp:Wss11 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
          <wsp:Policy />
        </sp:Wss11>
        <sp:Trust10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
          <wsp:Policy>
            <sp:MustSupportIssuedTokens />
            <sp:RequireClientEntropy />
            <sp:RequireServerEntropy />
          </wsp:Policy>
        </sp:Trust10>
        <wsaw:UsingAddressing />
      </wsp:All>
    </wsp:ExactlyOne>
  </wsp:Policy>
  <wsp:Policy wsu:Id="WSHttpBinding_IDialler_DiallerProcess_Input_policy">
    <wsp:ExactlyOne>
      <wsp:All>
        <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
          <sp:Body />
          <sp:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing" />
          <sp:Header Name="From" Namespace="http://www.w3.org/2005/08/addressing" />
          <sp:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing" />
          <sp:Header Name="ReplyTo" Namespace="http://www.w3.org/2005/08/addressing" />
          <sp:Header Name="MessageID" Namespace="http://www.w3.org/2005/08/addressing" />
          <sp:Header Name="RelatesTo" Namespace="http://www.w3.org/2005/08/addressing" />
          <sp:Header Name="Action" Namespace="http://www.w3.org/2005/08/addressing" />
        </sp:SignedParts>
        <sp:EncryptedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
          <sp:Body />
        </sp:EncryptedParts>
      </wsp:All>
    </wsp:ExactlyOne>
  </wsp:Policy>
  <wsp:Policy wsu:Id="WSHttpBinding_IDialler_DiallerProcess_output_policy">
    <wsp:ExactlyOne>
      <wsp:All>
        <sp:SignedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
          <sp:Body />
          <sp:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing" />
          <sp:Header Name="From" Namespace="http://www.w3.org/2005/08/addressing" />
          <sp:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing" />
          <sp:Header Name="ReplyTo" Namespace="http://www.w3.org/2005/08/addressing" />
          <sp:Header Name="MessageID" Namespace="http://www.w3.org/2005/08/addressing" />
          <sp:Header Name="RelatesTo" Namespace="http://www.w3.org/2005/08/addressing" />
          <sp:Header Name="Action" Namespace="http://www.w3.org/2005/08/addressing" />
        </sp:SignedParts>
        <sp:EncryptedParts xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
          <sp:Body />
        </sp:EncryptedParts>
      </wsp:All>
    </wsp:ExactlyOne>
  </wsp:Policy>
  <wsdl:types>
    <xsd:schema targetNamespace="http://tempuri.org/Imports">
      <xsd:import schemaLocation="http://localhost:56435/Service.svc?xsd=xsd0" namespace="http://tempuri.org/" />
      <xsd:import schemaLocation="http://localhost:56435/Service.svc?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/" />
      <xsd:import schemaLocation="http://localhost:56435/Service.svc?xsd=xsd2" namespace="http://schemas.datacontract.org/2004/07/WCFServiceDialler" />
      <xsd:import schemaLocation="http://localhost:56435/Service.svc?xsd=xsd3" namespace="http://schemas.datacontract.org/2004/07/LeadTransfer.DiallerData.DataContracts.Car.Aviva" />
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="IDialler_DiallerProcess_InputMessage">
    <wsdl:part name="parameters" element="tns:DiallerProcess" />
  </wsdl:message>
  <wsdl:message name="IDialler_DiallerProcess_OutputMessage">
    <wsdl:part name="parameters" element="tns:DiallerProcessResponse" />
  </wsdl:message>
  <wsdl:portType name="IDialler">
    <wsdl:operation name="DiallerProcess">
      <wsdl:input wsaw:Action="http://tempuri.org/IDialler/DiallerProcess" message="tns:IDialler_DiallerProcess_InputMessage" />
      <wsdl:output wsaw:Action="http://tempuri.org/IDialler/DiallerProcessResponse" message="tns:IDialler_DiallerProcess_OutputMessage" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="WSHttpBinding_IDialler" type="tns:IDialler">
    <wsp:PolicyReference URI="#WSHttpBinding_IDialler_policy" />
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="DiallerProcess">
      <soap12:operation soapAction="http://tempuri.org/IDialler/DiallerProcess" style="document" />
      <wsdl:input>
        <wsp:PolicyReference URI="#WSHttpBinding_IDialler_DiallerProcess_Input_policy" />
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <wsp:PolicyReference URI="#WSHttpBinding_IDialler_DiallerProcess_output_policy" />
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="Service">
    <wsdl:port name="WSHttpBinding_IDialler" binding="tns:WSHttpBinding_IDialler">
      <soap12:address location="http://localhost:56435/Service.svc/ws" />
      <wsa10:EndpointReference>
        <wsa10:Address>http://localhost:56435/Service.svc/ws</wsa10:Address>
        <Identity xmlns="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity">
          <Upn>Pandeysi@cis.ad.capita.co.uk</Upn>
        </Identity>
      </wsa10:EndpointReference>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

第一个 LTService 应用程序的配置:

<system.serviceModel>
<services>
  <service behaviorConfiguration="http" name="TestCDLWCF.Service">
    <endpoint address="wstest" binding="wsHttpBinding" contract="TestCDLWCF.ILeadTransfer">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8732/Design_Time_Addresses/TestCDLWCF/Service1/" />
      </baseAddresses>
    </host>
  </service>
  <service name="WCFServiceDialler.Service">
    <endpoint address="ws" binding="wsHttpBinding" bindingConfiguration=""
      contract="WCFServiceDialler.IDialler" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8732/Design_Time_Addresses/WCFServiceDialler/Service/mex" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="http">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>

  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

WCFServiceDialler 应用程序的配置:

    <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="binding" />
      </wsHttpBinding>
    </bindings>
    <services>
      <service name="WCFServiceDialler.Service">
        <endpoint address="ws" binding="wsHttpBinding" bindingConfiguration="binding"
          contract="WCFServiceDialler.IDialler" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/WCFServiceDialler/Service/mex" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

我的项目中使用 wcfdiallerservice 的配置:

 <system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IDialler" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" />
                </security>
            </binding>
            <binding name="WSHttpBinding_IDialler1" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" />
                </security>
            </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost/Service.svc/ws" binding="wsHttpBinding"
            bindingConfiguration="WSHttpBinding_IDialler" contract="WCFServiceDialler.IDialler"
            name="WSHttpBinding_IDialler">
            <identity>
                <servicePrincipalName value="host/CIDDTS4FCMG4.cis.ad.capita.co.uk" />
            </identity>
        </endpoint>
        <endpoint address="http://localhost:56435/Service.svc/ws" binding="wsHttpBinding"
            bindingConfiguration="WSHttpBinding_IDialler1" contract="DiallerServiceReference.IDialler"
            name="WSHttpBinding_IDialler1">
        </endpoint>
    </client>
</system.serviceModel>
4

1 回答 1

1

在您的服务客户端中,您正在创建客户端对象的实例并将其传递给应该存在于配置文件中的端点的名称:

LeadTransfer.PartnerContracts.DiallerServiceReference.DiallerClient client = new LeadTransfer.PartnerContracts.DiallerServiceReference.DiallerClient("wsHttpBinding"); 

您已在客户端配置文件中定义了以下端点:

    <client>  
        <endpoint address="http://localhost/Service.svc/ws" binding="wsHttpBinding"  
            bindingConfiguration="WSHttpBinding_IDialler" contract="WCFServiceDialler.IDialler"  
            name="WSHttpBinding_IDialler">  
            <identity>  
                <servicePrincipalName value="host/CIDDTS4FCMG4.cis.ad.capita.co.uk" />  
            </identity>  
        </endpoint>  
        <endpoint address="http://localhost:56435/Service.svc/ws" binding="wsHttpBinding"  
            bindingConfiguration="WSHttpBinding_IDialler1" contract="DiallerServiceReference.IDialler"  
            name="WSHttpBinding_IDialler1">  
        </endpoint>  
    </client>  

基本上,您是在告诉您的客户端对象从配置中名为“wsHttpBinding”的端点节点加载其配置,但唯一可用的端点名为“WSHttpBinding_IDialler”和“WSHttpBinding_IDialler1”。

解决方案是通过指向现有端点配置来更新创建客户端对象的方式,如下所示:

LeadTransfer.PartnerContracts.DiallerServiceReference.DiallerClient client = new LeadTransfer.PartnerContracts.DiallerServiceReference.DiallerClient("WSHttpBinding_IDialler");
于 2012-08-23T15:59:01.747 回答