c# - "There was no endpoint listening"- 可能是配置不匹配?

标签 c# wcf iis

我明白了

"There was no endpoint listening at https://localhost/BassCoastServices/GeneralUtilityService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details."



当我从客户端调用 GeneralUtilityService 并且

"There was no channel actively listening at 'https://laura-laptop/BassCoastServices/GeneralUtilityService.svc'. This is often caused by an incorrect address URI. Ensure that the address to which the message is sent matches an address on which a service is listening."



当我调试 w3wp 时出现。

我可以使用某种工具来确保客户端和服务器配置文件对齐吗?
如果这是一个简单的修复,请参阅下面的 App 和 Web 配置文件。

应用程序配置
<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="Username" value="sampleuser"/>
    <add key="Password" value="samplepassword"/>
    <add key="basePath" value="C:\Temp"/>
  </appSettings>

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <bindings>
      <wsHttpBinding>
        <binding name="standardBinding" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" allowCookies="true">
          <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="163840" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
          <reliableSession ordered="true" inactivityTimeout="01:00:00" enabled="false"/>
          <security mode="TransportWithMessageCredential" >
            <transport clientCredentialType="Certificate" proxyCredentialType="None"  />
            <message clientCredentialType="UserName" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="ClientCertificateBehavior">
          <callbackDebug includeExceptionDetailInFaults="true"/>
          <clientCredentials>
            <clientCertificate findValue="localhost" x509FindType="FindByIssuerName" storeLocation="LocalMachine" storeName="My">
            </clientCertificate>
          </clientCredentials>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <client>

      <endpoint address="https://localhost/BassCoastServices/GeneralUtilityService.svc" behaviorConfiguration="ClientCertificateBehavior" binding="wsHttpBinding" bindingConfiguration="standardBinding" contract="Adapt.WCF.IGeneralUtilityService" name="IGeneralUtilityServiceEndPoint">
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>

    </client>
  </system.serviceModel>

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
  </startup>
</configuration>

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

  <appSettings>

    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
    <add key="DatabaseConnectionString" value="Data Source=(local)\SQL2014;Initial Catalog=XIVICProduction;User ID=sa;Password=sameplepassword;MultipleActiveResultSets=True"/>
    <add key="LogFilePath" value="C:\inetpub\wwwroot\Xivic\BassCoastServices\Log\Log.txt"/>
    <add key="AllowMissingExternalIDs" value="true"/>

    <!--No need to change-->
    <add key="LogFileTypeLevel" value="Error"/>
    <add key="SqlServerDateTimeStyle" value="103"/>
    <add key="DatabaseType" value="Sql"/>
    <add key="EnforceSecurityAtBusinessRulesLayer" value="false"/>
    <add key="DateComparisonInaccuracy" value="35000"/>
    <add key="CacheAccessItemsAtBusinessLayer" value="true"/>
    <add key="CacheRecordsAtDataLayer" value="true"/>
    <add key="SesionTimeout" value="1440"/>
  </appSettings>

  <system.serviceModel>

    <services>
      <!-- ENDPOINTS -->
      <service name="IGeneralUtilityServiceEndPoint" behaviorConfiguration="UserNameBehaviour">
        <endpoint binding="wsHttpBinding" contract="Adapt.WCF.IGeneralUtilityService" bindingConfiguration="wsHttpEndpointBinding"/>
      </service>

    </services>

    <!-- BEHAVIOURS -->
    <behaviors>
      <serviceBehaviors>
        <behavior name="UserNameBehaviour">
          <serviceThrottling maxConcurrentCalls="2147483647" maxConcurrentInstances="2147483647" maxConcurrentSessions="2147483647" />
          <serviceDebug includeExceptionDetailInFaults="True" />
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Adapt.WCF.Security.CustomUserNameValidator, Adapt.WCF" />
            <serviceCertificate findValue="localhost" x509FindType="FindByIssuerName" storeLocation="LocalMachine" storeName="My">
            </serviceCertificate>
          </serviceCredentials>
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <!-- BINDINGS -->
    <bindings>

      <wsHttpBinding>
        <binding name="wsHttpEndpointBinding">
          <security mode="TransportWithMessageCredential">
            <transport clientCredentialType="None" />
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>

    </bindings>

  </system.serviceModel>

  <system.diagnostics>
        <sources>
            <source name="System.ServiceModel"
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true">
                <listeners>
                    <add name="traceListener"
                        type="System.Diagnostics.XmlWriterTraceListener"
                        initializeData= "C:\inetpub\wwwroot\Xivic\BassCoastServices\Log\Traces.svclog" />
                </listeners>
            </source>
        </sources>
    </system.diagnostics>

  <!--startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
  </startup-->

</configuration>

调用 WCF
_Channel = GetProxy<IGeneralUtilityService>();
_Channel.BeginTransaction(transactionId);
_Channel.CommitTransaction(transactionId);

public static T GetProxy<T>()
{
    var channelFactory = new ChannelFactory<T>(string.Format("{0}EndPoint", typeof(T).Name));
    channelFactory.Credentials.UserName.UserName = ConfigurationSettings.AppSettings["Username"];
    channelFactory.Credentials.UserName.Password = ConfigurationSettings.AppSettings["Password"];
    var workflowProxy = channelFactory.CreateChannel();
    return workflowProxy;
}

提前致谢!

更新:我不知道我做了什么,但现在我得到了

"Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost/BassCoastServices/GeneralUtilityService.svc. The client and service bindings may be mismatched."

最佳答案

您的问题是您创建 channel 工厂的方式。有些如何无法获得正确的 EndpointConfigurationName。

我不太熟悉如何在 Channel Factory 中仅使用 EndpointConfigurationName 作为参数,但您可以这样尝试:

var channelFactory = new ChannelFactory<T>("*", new EndpointAddress("https://localhost/BassCoastServices/GeneralUtilityService.svc"));

关于c# - "There was no endpoint listening"- 可能是配置不匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32600624/

相关文章:

c# - 每个用户在窗口内选择随机时间的算法

c# - 使用 C# 获取当前位置

c# - Mono:非 SSL URI 上的 HttpWebRequest SSL 错误

c# - 网页访问问题

git - Bonobo Git 服务器 - HTTP 错误 500.19 - 代码 : 0x80070021

.net - WCF 自托管服务是否比 IIS 托管选项处理更多或更少的负载?

c# - 如何在 Windows 中使用 UniDrv 或 XPS 驱动程序 v3 设置虚拟打印机和显示器

xml - WCF 4.0 Rest 服务设置内容类型

c# - 错误 : "Could not load file or assembly System.Web.WebPages.Razor"

wcf - 使用 WCF RESTFul 服务完整工作示例上传图像