WCF - 从另一个 Web 应用程序(WCF 或 REST API)调用时的 EndpointNotFoundException

WCF - EndpointNotFoundException when calling from another Web Application (WCF or REST API)

提问人:w0dapl 提问时间:2/23/2021 更新时间:2/23/2021 访问量:60

问:

最近,我在 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 服务 WCF 异常

评论


答:

0赞 Ding Peng 2/23/2021 #1

首先,您必须确保 WCF 服务已启动,可以通过浏览器检查 WCF 服务是否已启动:

enter image description here

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

enter image description here

enter image description here

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

enter image description here

评论

0赞 w0dapl 2/23/2021
我启动并正常工作,除了外部 WCF 调用。可能我在上面已经提到过了。
0赞 Ding Peng 2/23/2021
external call 是什么意思?是因为网络被封锁了吗?
0赞 Ding Peng 2/23/2021
终结点地址:您可以尝试使用 IP 地址。
0赞 w0dapl 2/23/2021
外部调用意味着我已经创建了 WCF 服务,我现在在 localhost 上运行,它具有上面提到的带有登录和传递的外部连接服务引用(它是测试服务,所以我不担心该数据)。有了它,我无法连接 SocketException 和 timeout(但从控制台应用程序模板项目中,我可以,所以可能是我假设的 web.config 中的东西)。https://uslugaterytws1test.stat.gov.pl/wsdl/terytws1.wsdl
0赞 w0dapl 2/24/2021
案件已结案。问题是我的公司代理与Web服务外部连接。因此,我在 <httpsTransport /> 中添加了代理地址和标志,一切正常。