C# 自托管Wcf提供wsdl,但404';当被调用时

C# 自托管Wcf提供wsdl,但404';当被调用时,c#,web-services,wcf,soap,wsdl,C#,Web Services,Wcf,Soap,Wsdl,我正在尝试自托管一个服务的单例实例,很明显,我在间接层次上迷失了方向 我有一个http://localhost:8050/。我不太在意服务端点在哪里,只要它是可预测的。目前,我正在尝试使用/Manage/ 我能够浏览到基址并看到wsdl。如果我浏览wsdl,它会指向/Manage/ <wsdl:service name="EngineService"> <wsdl:port name="BasicHttpBinding_IEngineService" binding="

我正在尝试自托管一个服务的单例实例,很明显,我在间接层次上迷失了方向

我有一个
http://localhost:8050/
。我不太在意服务端点在哪里,只要它是可预测的。目前,我正在尝试使用
/Manage/

我能够浏览到基址并看到wsdl。如果我浏览wsdl,它会指向
/Manage/

<wsdl:service name="EngineService">
    <wsdl:port name="BasicHttpBinding_IEngineService" binding="tns:BasicHttpBinding_IEngineService">
        <soap:address location="http://localhost:8050/Manage/"/>
    </wsdl:port>
</wsdl:service>
日志消息显示从未调用我的实例方法。该服务没有进入故障状态,只是看起来不存在

我在听以下内容:

    public static ServiceHost Listen<TServiceContract>(
            TServiceContract instance,
            int port,
            string name
        ) {

        //Added this for debugging, was previously just "name"
        string endpoint = String.Format("http://localhost:{0}/{1}/", port, name);

        var svcHost = new ServiceHost(
            instance,
            new Uri[] { new Uri(String.Format("http://localhost:{0}/", port)) });

        /* Snip: Add a Faulted handler but it's never called */

        ServiceEndpoint serviceHttpEndpoint = svcHost.AddServiceEndpoint(
            typeof(TServiceContract),
            new BasicHttpBinding {
                HostNameComparisonMode = HostNameComparisonMode.WeakWildcard
            }, endpoint); /*Using name instead of endpoint makes no difference beyond removing the trailing slash */

        /* Snip: Add a ServiceDebugBehavior with IncludeExceptionDetailInFaults = true */
        /* Snip: Add a ServiceMetadataBehavior with HttpGetEnabled = true */

        try {
            log.Trace("Opening endpoint");
            svcHost.Open();
        } catch () {
            /* Lots of catches for different problems including Exception
             * None of them get hit */
        }


        log.Info("Service contract {0} ready at {1}", typeof(TServiceContract).Name, svcHost.BaseAddresses.First());
        return svcHost;
        IEngineService wcfInstance = Resolver.Resolve<IEngineService>();
        service = WcfHoster.Listen(wcfInstance, 8050, "Manage");
我如何进一步跟踪问题所在/调试

其他信息:服务合同和最低限度实施:

[ServiceContract]
interface IEngineService {
    [OperationContract]
    List<string> Agents();

    [OperationContract]
    string Test();

    [OperationContract]
    List<string> SupportedAgents();

    [OperationContract]
    string Connect(string AgentStrongName, string Hostname);
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
class EngineService : IEngineService {
    IAgentManager agentManager;
    public EngineService(IAgentManager AgentManager) {
        log.Debug("Engine webservice instantiating");
        this.agentManager = AgentManager;
    }

    public string Connect(string AgentStrongName, string Hostname) {
        log.Debug("Endpoint requested for [{0}], [{1}]", Hostname, AgentStrongName);
        return agentManager.GetSession(AgentStrongName, Hostname);
    }

    public List<string> Agents() {
        log.Debug("Current agents queried");
        throw new NotImplementedException();
    }

    public List<string> SupportedAgents() {
        log.Debug("Supported agents queried");
        return agentManager.SupportedAgents().ToList();
    }

    public string Test() {
        log.Warn("Test query");
        return "Success!";
    }
}
[服务合同]
接口服务{
[经营合同]
列出代理();
[经营合同]
字符串测试();
[经营合同]
列出支持的代理();
[经营合同]
字符串连接(字符串代理TrongName、字符串主机名);
}
以及实施:

[ServiceContract]
interface IEngineService {
    [OperationContract]
    List<string> Agents();

    [OperationContract]
    string Test();

    [OperationContract]
    List<string> SupportedAgents();

    [OperationContract]
    string Connect(string AgentStrongName, string Hostname);
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
class EngineService : IEngineService {
    IAgentManager agentManager;
    public EngineService(IAgentManager AgentManager) {
        log.Debug("Engine webservice instantiating");
        this.agentManager = AgentManager;
    }

    public string Connect(string AgentStrongName, string Hostname) {
        log.Debug("Endpoint requested for [{0}], [{1}]", Hostname, AgentStrongName);
        return agentManager.GetSession(AgentStrongName, Hostname);
    }

    public List<string> Agents() {
        log.Debug("Current agents queried");
        throw new NotImplementedException();
    }

    public List<string> SupportedAgents() {
        log.Debug("Supported agents queried");
        return agentManager.SupportedAgents().ToList();
    }

    public string Test() {
        log.Warn("Test query");
        return "Success!";
    }
}
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
类别EngineService:IEEngineService{
IAgentManager代理管理者;
公共工程服务(IAgentManager代理管理者){
调试(“引擎Web服务实例化”);
this.agentManager=agentManager;
}
公共字符串连接(字符串代理TrongName、字符串主机名){
Debug(“为[{0}]、{1}]请求的端点”、主机名、AgentStrongName);
返回agentManager.GetSession(AgentStrongName,主机名);
}
公开名单代理人(){
log.Debug(“查询的当前代理”);
抛出新的NotImplementedException();
}
公共列表支持代理(){
log.Debug(“受支持的查询代理”);
return agentManager.SupportedAgents().ToList();
}
公共字符串测试(){
log.Warn(“测试查询”);
返回“成功!”;
}
}
测试客户端可以看到服务和方法,但当我单击Invoke时会抛出上面的异常

编辑:localhost默认解析为IPv6,所以我尝试在两端显式使用127.0.0.1。没有区别

我曾尝试将上述代码引入一个新项目,但也遇到了同样的问题。在别人的机器上运行整件事也没用

服务跟踪查看器 在服务器端运行,然后在查看器中检查结果,可以得到:

无法查找接收传入消息的通道。找不到终结点或SOAP操作


配置文件:因为我需要可执行文件来决定在运行时显示哪个Wcf服务,所以配置文件中没有任何与Wcf相关的代码。

这可能是客户端/服务绑定不匹配。请检查测试客户端绑定。您还应该通过从wsdl生成代理来创建单元测试


嗯。我试图重现您的问题,并通过删除“HostNameComparisonMode=HostNameComparisonMode.WeakWildcard”来调用主机,以获得默认的basichttp端点。你为什么需要这个?

你的异常发生在哪一行代码中?在使用服务的客户端,而不是进程宿主服务本身,因此我的调试困难。请你更具体地说,像在try catch或其他地方一样。我的实际捕获有
通信对象FaultedException的块,
TimeoutException
Exception
。他们没有一个人被击中。就我从主机进程所知,服务加载良好,提供wsdl等。。。只是当调用任何方法时,我在客户端得到一个404。据我所知,主持人甚至没有看到那个电话。我显示的异常消息来自于VisualStudio附带的Wcf测试客户机,该客户机用于测试消费web服务。如果你能澄清你想要抓什么,我会加上一个try/catch。对不起,我不能再帮你了。当您修复它时,请告诉我:)祝您好运。如问题中所述,客户端是WcfTestClient,它完全从Wsdl生成配置和绑定。自动生成的绑定的客户端节点如下所示:
有趣的是,这是由于以这种形式提供BaseUri时出现了一个问题:
http://*:1234/
http://+:1234/
在代码中引发了异常。(这些方法使用的是
Uri[]
,而Uri类在使用通配符语法时抱怨主机名无效。
0.0.0
有效,但Wsdl在链接中使用的
0.0.0.0
无效。从文档
WeakWildcard:如果没有找到强匹配或精确匹配,则在匹配时忽略主机名。
)。让我测试一下,然后再给你回复,谢谢你的提示,删除
HostNameComparisonMode=HostNameComparisonMode.WeakWildcard
成功了。谢谢你的帮助,我希望赏金能给你一个好的开始。Thx,WCF是我最喜欢的.Net技术。我希望你也会喜欢。