最近,我在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) { }
发布于 2021-02-23 15:03:13
首先你要确保你的WCF服务已经启动,你可以通过浏览器检查WCF服务是否已经启动:
然后,您可以通过添加服务引用来调用WCF服务:
点击OK后,会自动生成proxy类,我们可以通过proxy类调用WCF服务:
https://stackoverflow.com/questions/66327478
复制相似问题