C# 创建回调WCF服务时EndpointNotFoundException
我正在尝试基于的WCF回调服务的自托管 以下是托管代码: 服务:C# 创建回调WCF服务时EndpointNotFoundException,c#,wcf,C#,Wcf,我正在尝试基于的WCF回调服务的自托管 以下是托管代码: 服务: static void Main(string[] args) { using (ServiceHost host = new ServiceHost(typeof(Message), new Uri("http://localhost:8000/HelloWCF"))) { // Set up a service endpoint [Contract, Bindin
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(Message), new Uri("http://localhost:8000/HelloWCF")))
{
// Set up a service endpoint [Contract, Binding, Address]
host.AddServiceEndpoint(typeof(IMessage), new WSDualHttpBinding() { ClientBaseAddress = new Uri("http://locahost:8001/HelloWCF") }, "HelloWCF");
// Enable metadata exchange
ServiceMetadataBehavior smb = new ServiceMetadataBehavior() {HttpGetEnabled =true };
host.Description.Behaviors.Add(smb);
host.Open();
Console.WriteLine("Ready...");
Console.ReadLine();
}
}
客户:
app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsDualHttpBinding >
<binding name="WSDualHttpBinding_IMessage" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" clientBaseAddress="http://locahost:8001/HelloWCF">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8000/HelloWCF/HelloWCF" binding="wsDualHttpBinding"
bindingConfiguration="WSDualHttpBinding_IMessage" contract="CallbackService.IMessage"
name="WSDualHttpBinding_IMessage" >
<identity>
<userPrincipalName value="badasscomputing\menkaur" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
内部异常是:无法连接到远程服务器
这不是因为防火墙,因为我在没有回调函数的情况下成功测试了一个类似的应用程序
这可能是什么原因
已更新
完整的源代码可以在这里下载:您似乎在托管您的端点,但您的客户端配置指向(注意:extra“/HelloWCF”) 更新
您的客户端配置契约设置为
CallbackService.IMessage
,但您的代码中没有IMessage契约的服务实现。您似乎在托管端点,但您的客户端配置指向(注意:extra“/HelloWCF”)
更新
您的客户端配置契约设置为
CallbackService.IMessage
,但您的代码中没有一个IMessage契约的服务实现。通过这些小更改,您的代码在我的机器上运行良好
客户端配置
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IMessage" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8000/HelloWCF" binding="wsDualHttpBinding"
bindingConfiguration="WSDualHttpBinding_IMessage" contract="CallbackService.IMessage"
name="WSDualHttpBinding_IMessage">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
通过这些小改动,您的代码在我的机器上运行良好 客户端配置
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IMessage" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8000/HelloWCF" binding="wsDualHttpBinding"
bindingConfiguration="WSDualHttpBinding_IMessage" contract="CallbackService.IMessage"
name="WSDualHttpBinding_IMessage">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
另外,我喜欢您的计算机/域名BadasComputing另外,我喜欢您的计算机/域名BadasComputing如果我将客户端端点设置为,内部异常将更改为404。服务器正在运行IMessage是服务器端接口。它希望向IMessageCallback发送回调消息,IMessageCallback在客户端上实现。因此,您可以为该接口包含服务契约和服务实现代码吗?如果我将客户端端点设置为,则内部异常将更改为404。服务器正在运行IMessage是服务器端接口。它希望向IMessageCallback发送回调消息,IMessageCallback是在客户端上实现的。那么,您是否可以包含此接口的服务契约和服务实现代码?通过这些更改,我得到了“HTTP无法注册URL HTTP://+:80/Temporary_Listen_Addresses/9b0d36c7-c04e-4204-9a7c-eb887b03f3c9/,因为TCP端口80正被另一个应用程序使用。“如果您只是将ClientBaseAddress更改为其他端口,您应该可以。我自己刚刚意识到。添加ClientBaseAddress=”“到配置/system.serviceModel/bindings/wsDualHttpBinding/binding已完成。我的错误是设置clientBaseAddress=“”,通过这些更改,我得到了“HTTP无法注册URL HTTP://+:80/临时_Listen_Addresses/9b0d36c7-c04e-4204-9a7c-eb887b03f3c9/,因为TCP端口80正被另一个应用程序使用。”如果您只是将clientBaseAddress更改为其他端口,您应该可以。我自己刚刚意识到这一点。向configuration/system.serviceModel/bindings/wsDualHttpBinding/binding添加clientBaseAddress=“”已完成。我的错误是设置clientBaseAddress=“”
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IMessage" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="Message">
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8000/HelloWCF" binding="wsDualHttpBinding"
bindingConfiguration="WSDualHttpBinding_IMessage" contract="CallbackService.IMessage"
name="WSDualHttpBinding_IMessage">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
namespace wcfStarter
{
class Program
{
static void Main(string[] args)
{
using (ServiceHost host = new ServiceHost(typeof(Message), new Uri("http://localhost:8002/HelloWCF")))
{
// Set up a service endpoint [Contract, Binding, Address]
host.AddServiceEndpoint(typeof(IMessage), new WSDualHttpBinding() { ClientBaseAddress = new Uri("http://locahost:8001") }, "HelloWCF");
// Enable metadata exchange
ServiceMetadataBehavior smb = new ServiceMetadataBehavior() {HttpGetEnabled =true };
host.Description.Behaviors.Add(smb);
host.Open();
Console.WriteLine("Ready...");
Console.ReadLine();
}
}
}
}