gpt4 book ai didi

c# - 自托管 Wcf 服务于 wsdl 但在调用时为 404

转载 作者:太空狗 更新时间:2023-10-29 19:43:55 25 4
gpt4 key购买 nike

我正在尝试自行托管服务的单例实例,但显然我在间接级别上迷路了...

我有一个基地址 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: There was no endpoint listening at http://localhost:8050/Manage that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

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

编辑:本地主机默认解析为 IPv6,所以我尝试在两端明确使用 127.0.0.1。没有区别。

我尝试将上述代码放入一个新项目中,但遇到了同样的问题。在别人的机器上运行整个过程也无济于事。

服务跟踪查看器

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

Failed to lookup a channel to receive an incoming message. Either the endpoint or the SOAP action was not found.

enter image description here

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

最佳答案

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

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

关于c# - 自托管 Wcf 服务于 wsdl 但在调用时为 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29749104/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com