Bas*_*sic 8 c# wcf soap wsdl web-services
我正在尝试自我托管一个服务的单例实例,我显然在间接层面迷失了......
我有一个基地址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>
Run Code Online (Sandbox Code Playgroud)
当我使用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)
Run Code Online (Sandbox Code Playgroud)
日志消息显示我的实例方法永远不会被调用.该服务不会进入故障状态,只是看起来不存在.
我正在听如下:
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;
Run Code Online (Sandbox Code Playgroud)
并调用Listen()方法如下:
IEngineService wcfInstance = Resolver.Resolve<IEngineService>();
service = WcfHoster.Listen(wcfInstance, 8050, "Manage");
Run Code Online (Sandbox Code Playgroud)
如何进一步追踪问题/调试?
附加信息:服务合同和最小化实施:
[ServiceContract]
interface IEngineService {
[OperationContract]
List<string> Agents();
[OperationContract]
string Test();
[OperationContract]
List<string> SupportedAgents();
[OperationContract]
string Connect(string AgentStrongName, string Hostname);
}
Run Code Online (Sandbox Code Playgroud)
并实施:
[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!";
}
}
Run Code Online (Sandbox Code Playgroud)
测试客户端可以看到服务和方法,但是当我单击Invoke时会抛出上面的异常...

编辑:localhost默认解析为IPv6,所以我尝试在两端显式使用127.0.0.1.没有不同.
我已尝试将上述代码纳入新项目并获得相同的问题.在别人的机器上运行整个事情也没有帮助.
在服务器端运行服务跟踪,然后在查看器中检查结果给出:
无法查找频道以接收传入消息.找不到端点或SOAP操作.

配置文件:由于我需要可执行文件才能决定在运行时呈现哪个Wcf服务,因此配置文件中没有任何与Wcf相关的代码.
这可能是客户端/服务绑定不匹配。请检查测试客户端绑定。您还应该通过从 wsdl 生成代理来创建单元测试。
好的。我尝试重现您的问题,并通过删除“HostNameComparisonMode = HostNameComparisonMode.WeakWildcard”来设法调用主机,以获得默认的 basichttp 端点。为什么需要这个?
| 归档时间: |
|
| 查看次数: |
993 次 |
| 最近记录: |