自托管Wcf在调用时提供wsdl但404

时间:2015-04-20 13:21:30

标签: c# web-services wcf soap wsdl

我正在尝试自我托管一个服务的单例实例,我显然迷失在间接层面......

我的基地址为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>

当我使用WcfTestClient使用wsdl时,它列出了所有正确的方法,但是调用它们中的任何一个会抛出以下异常

  

System.ServiceModel.EndpointNotFoundException:http://localhost:8050/Manage没有可以接受该消息的端点。这通常是由错误的地址或SOAP操作引起的。有关更多详细信息,请参阅InnerException(如果存在)。

Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at IEngineService.SupportedAgents()
   at EngineServiceClient.SupportedAgents()

Inner Exception:
The remote server returned an error: (404) Not Found.
   at System.Net.HttpWebRequest.GetResponse()
   at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

日志消息显示我的实例方法永远不会被调用。该服务不会进入故障状态,只是看起来不存在。

我正在听如下:

    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;

调用Listen()方法如下:

        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!";
    }
}

测试客户端可以看到服务和方法,但是当我单击Invoke ...

时会抛出上面的异常

enter image description here

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

我已尝试将上述代码纳入新项目并获得相同的问题。在别人的机器上运行整个事情也没有帮助。

服务跟踪查看器

在服务器端运行service trace,然后在查看器中检查结果:

  

无法查找频道以接收传入消息。找不到端点或SOAP操作。

enter image description here

配置文件:由于我需要可执行文件才能决定在运行时呈现哪个Wcf服务,因此配置文件中没有任何与Wcf相关的代码。

1 个答案:

答案 0 :(得分:3)

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

确定。我试图重现你的问题,我通过删除&#34; HostNameComparisonMode = HostNameComparisonMode.WeakWildcard&#34;来管理主机。为了获得默认的basichttp端点。你为什么需要这个?