【发布时间】:2015-03-16 19:41:11
【问题描述】:
我的 WCF 服务有问题,这些方法本身会收集正确的数据并返回正确的数据类型,但是无论我为端点使用哪种绑定类型,我总是会遇到相同的错误。我试过 TCP、HTTP 和 NamedPipe。顶部的一般错误如下:
调用服务失败。可能原因:服务离线 或无法访问;客户端配置不匹配 代理;现有代理无效。请参阅堆栈跟踪 更多详情。您可以尝试通过启动新代理来恢复,恢复 到默认配置,或者刷新服务。
发布的内容来自 HTTP 绑定。
An error occurred while receiving the HTTP response to http://localhost:8732/ClubService/. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs 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.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)
at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)
at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Security.SecuritySessionClientSettings`1.SecurityRequestSessionChannel.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 IAndereBoekenService.BoekBeschikbaar(String isbn)
at AndereBoekenServiceClient.BoekBeschikbaar(String isbn)
Inner Exception:
The underlying connection was closed: An unexpected error occurred on a receive.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
Inner Exception:
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
Inner Exception:
An existing connection was forcibly closed by the remote host
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="ClubServiceLibrary.ClubService">
<host>
<baseAddresses>
<add baseAddress="net.pipe://localhost/ClubService" />
<add baseAddress ="net.tcp://localhost/ClubService" />
<add baseAddress="http://localhost:8732/ClubService/" />
</baseAddresses>
</host>
<endpoint name ="namedPipeClub"
binding="netNamedPipeBinding"
contract="ClubServiceLibrary.IClubServiceLibrary" />
<endpoint name="namedPipeClubMEX"
address="mex"
binding="mexNamedPipeBinding"
contract="IMetadataExchange" />
<endpoint name ="tcpClub"
binding="netTcpBinding"
contract="ClubServiceLibrary.IClubServiceLibrary" />
<endpoint name="tcpClubMEX"
address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange" />
<endpoint binding="wsHttpBinding"
name="httpClub"
contract="ClubServiceLibrary.IClubServiceLibrary" />
<endpoint address="mex"
binding="mexHttpBinding"
name="httpClubMEX"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
我正在从一个字典中获取我的数据,该字典中填充了另一个名为“DummyData”的类中的虚拟数据,这确实填充了数据。
private static Dictionary<int, Club> clubsValue;
public static Dictionary<int, Club> Clubs
{
get { return clubsValue; }
}
在我的 ClubService 类中,我执行以下操作:
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class ClubService : IClubService
{
public List<Club> GetClubByName(string search)
{
var searchToLower = search.ToLower();
List<Club> test = DummyData.Clubs.Values.Where(b => b.Titel.ToLower().Contains(searchToLower)).ToList();
return test;
}
}
我的 IClubInterface 如下所示:
[ServiceContract(Namespace = "http://club.com/clubservice")]
interface IClubService
{
[OperationContract]
List<Club> GetClubByName(string search);
}
所以当调试所有数据都在列表中时,我返回了正确的列表。但是每次我都收到这个错误消息,我不知道如何解决这个问题。
【问题讨论】: