【问题标题】:WCF - EndpointNotFoundException when calling from another Web Application (WCF or REST API)WCF - 从另一个 Web 应用程序(WCF 或 REST API)调用时出现 EndpointNotFoundException
【发布时间】:2021-05-25 09:22:26
【问题描述】:

最近我在 WCF 中从另一个 Web 应用程序(WCF 或 REST API)调用时遇到了 EndpointNotFoundException 的问题。

我正在尝试连接到需要登录名和密码识别的外部 WCF 服务(现在我正在处理提供商准备的测试环境)。

然后异常发生:

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

此问题不会出现在控制台应用程序中 - 运行顺畅,但仅在我创建简单项目(如 WCF 或 REST API)时才会出现。

<bindings>
      <customBinding>
        <binding name="custom">
          <security defaultAlgorithmSuite="Default" authenticationMode="UserNameOverTransport"
            requireDerivedKeys="true" includeTimestamp="true" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
            <localClientSettings detectReplays="false" />
            <localServiceSettings detectReplays="false" />
          </security>
          <textMessageEncoding messageVersion="Soap11WSAddressing10" />
          <httpsTransport maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"/>
        </binding>
      </customBinding>
    </bindings>
    <client>
      <endpoint address="https://uslugaterytws1test.stat.gov.pl/TerytWs1.svc"
        binding="customBinding" bindingConfiguration="custom" contract="TerytWsTest.ITerytWs1"
        name="custom" />
    </client>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
TerytWs1Client tc = new TerytWs1Client();
tc.ClientCredentials.UserName.UserName = "TestPubliczny";
tc.ClientCredentials.UserName.Password = "1234abcd";
var zalogowany = tc.CzyZalogowany();

我也试过了:

try { 
var proxy = new ChannelFactory<TerytWsTest.ITerytWs1>("custom");
proxy.Credentials.UserName.UserName = "TestPubliczny";
proxy.Credentials.UserName.Password = "1234abcd";
var result = proxy.CreateChannel();
var test = result.CzyZalogowany();
} 
catch (Exception ex) { }

【问题讨论】:

    标签: c# .net web-services wcf exception


    【解决方案1】:

    首先你要确保你的WCF服务已经启动,你可以通过浏览器查看WCF服务是否已经启动:

    然后就可以通过添加服务引用来调用WCF服务了:

    点击确定后会自动生成代理类,我们可以通过代理类调用WCF服务:

    【讨论】:

    • 我启动并正常工作,除了外部 WCF 调用。可能我上面已经提到过。
    • 外部调用是什么意思?是不是因为网络被封了?
    • 端点地址可以尝试使用IP地址。
    • 外部调用意味着我已经创建了 WCF 服务,该服务现在在 localhost 上运行,该服务具有外部连接服务引用 https://uslugaterytws1test.stat.gov.pl/wsdl/terytws1.wsdl 并通过上面提到的登录和通过(它是测试服务,所以我不是担心这些数据)。并且我无法连接 SocketException 和超时(但从控制台应用程序模板项目中我可以所以可能是 web.config 我假设的东西)。
    • 结案。问题是我的公司代理通过 Web 服务连接外部。所以我在 中添加了代理地址和标志,一切正常。
    猜你喜欢
    • 1970-01-01
    • 2012-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多