我该如何解决«无法查找频道以接收传入消息。找不到端点或SOAP操作»使用CustomBinding

时间:2019-01-09 21:28:49

标签: c# wcf custom-binding

我试图让配置有CustomBinding和SSL / TLC证书的WCF服务变得轻松,但是我每次都得到 System.ServiceModel.EndpointNotFoundException «https上没有侦听端点:// localhost /Helloword/HelloWord.svc,可以接受该消息。»

这是我的Service Web.config:

    <?xml version="1.0" encoding="utf-8"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.6.1" />
    <httpRuntime targetFramework="4.6.1"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyCustomBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceCredentials>
            <clientCertificate>
              <authentication certificateValidationMode="PeerTrust" trustedStoreLocation="LocalMachine" />
            </clientCertificate>
            <serviceCertificate findValue="ServerCert" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My"/>
          </serviceCredentials>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <customBinding>
        <binding name="MyCustomBinding">
          <textMessageEncoding />
          <security authenticationMode="CertificateOverTransport" requireSecurityContextCancellation="true"/>
          <httpsTransport authenticationScheme="IntegratedWindowsAuthentication" />
        </binding>
      </customBinding>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
      <service behaviorConfiguration="MyCustomBehavior" name="CustomBindingWifService.HelloWord">
        <host>
          <baseAddresses>
            <add baseAddress ="HelloWord.svc" />
          </baseAddresses>
        </host>
        <endpoint address="https://localhost/Helloword/HelloWord.svc" binding="customBinding"
            bindingConfiguration="MyCustomBinding" contract="CustomBindingWifService.IHelloWord">
          <identity>
            <certificateReference x509FindType="FindBySubjectName" findValue="ServerCert" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

还有我的客户端App.config

    <?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding name="MyCustomBinding">
          <textMessageEncoding />
          <security authenticationMode="CertificateOverTransport" requireSecurityContextCancellation="true"/>
          <httpsTransport />
        </binding>
      </customBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="MyCustomBehavior">
          <clientCredentials>
            <clientCertificate
            findValue="ClientCert"
            storeLocation="LocalMachine"
            storeName="My"
            x509FindType="FindBySubjectName" />
            <serviceCertificate>
              <authentication
              certificateValidationMode="PeerTrust"/>
            </serviceCertificate>
          </clientCredentials>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <client>
      <endpoint address="https://localhost/Helloword/HelloWord.svc"
        binding="customBinding" bindingConfiguration="MyCustomBinding"
        contract="ServiceHelloWord.IHelloWord" name="HelloWordEndPoint" 
        behaviorConfiguration="MyCustomBehavior" />
    </client>
  </system.serviceModel>
</configuration>

Program.cs:

namespace CustomBindingWifServiceClient
{
    public class Program
    {
        public static void Main(string[] args)
        {
            System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) => true;

            var channel = new ChannelFactory<ServiceHelloWord.IHelloWord>("HelloWordEndPoint");

            var client = channel.CreateChannel();

            var input = "Client Console";

            while (input != null && input.ToLower() != "exit")
            {
                var result = client.HelloWord(input);
                Console.WriteLine(result);
                input = Console.ReadLine();
            }
        }
    }
}

我收到以下错误:var result = client.HelloWord(input);

在浏览器中,服务看起来不错

enter image description here

感谢您的答复

0 个答案:

没有答案