WCF服务 - 未能调用服务 [英] WCF Service - Failed to invoke service

查看:153
本文介绍了WCF服务 - 未能调用服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的WCF服务的一个问题,这些方法本身收集正确的数据并返回正确的数据类型,但是我总是得到同样的错误,无论我使用的bindingtype我的端点。我试过TCP,HTTP和NamedPipe。顶部的一般错误如下:

I'm having a problem with my WCF Service, the methods itself collect the right data and return the correct datatypes however I always get the same error regardless of which bindingtype I use for my endpoints. I've tried TCP, HTTP and NamedPipe. The general error at the top is the following:

无法调用服务。可能的原因:服务是脱机
或无法访问;客户端配置不匹配,
代理;现有的代理是无效的。请参考$ B $堆栈轨迹B的更多细节。您可以尝试通过启动一个新的代理来恢复,恢复
默认配置,或刷新服务。

Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.

的模式。贴是从HTTP绑定

The one posted is from the HTTP binding.

 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,这也得到填充数据

I'm getting my data out of a dictionary which is filled up with dummy data in another class called "DummyData", this does get filled with data.

 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);
}



调试中的所有数据时

那么,在列表中,我回到了正确的列表。不过每一次我收到此错误信息,我不知道如何解决这个问题。

So when debugging all the data is in the list and I return the correct list.. however every single time I get this error messages and I have no idea how to resolve this.

推荐答案

如果我不得不猜的话,我会说序列化或返回时反序列化数据时,它会是这样的一个异常被抛出。最简单的方法来跟踪这个和放大器;大多数其他WCF错误是使WCF日志文件,看看什么它与WCF日志文件查看器中生成:

If I had to hazard a guess, I'd say it'll be something like an exception being thrown when serializing or deserializing your data upon return. The easiest way to track down this & most other WCF errors is to enable the WCF Log file and take a look at what it's generating with the WCF Log File viewer :

将以下部分添加到您的应用程序配置文件并确保其字迹的文件夹存在(C:在下面的示例\temp\WCFLogs)。
你应该开始看到一个ServerWCFTraces.svclog文件创建 - 它可能会说,在长度为0字节,直到你停止服务,或者决定刷新到磁盘

Add the following section to your application config file and then make sure the folder it is writing trace to exists (c:\temp\WCFLogs in the example below). You should start to see a ServerWCFTraces.svclog file be created - it might say 0 bytes in length until you stop your service or it decides to flush to disk.

一旦你的转载失败案例,打开使用Visual Studio在一台机器上的日志文件(或从这里下载的浏览器:的从MSDN SvcTraceViewer。)

Once you have reproduced your failure case, open up the log file on a machine with Visual Studio on (or download the viewer from here : SvcTraceViewer from MSDN.)

有一些指令使用的工具该MSDN链接,而是有效地你看看在活动窗格(左)错误(红色高亮显示),然后在零上失败的动作(右上窗格),并在细节部分(右下窗格)中,有将内部异常的描述正被抛出,几乎总是告诉你什么正被抛出的异常是,给你有关如何解决它的更多信息。

There's some instructions to use the tool on that MSDN link, but effectively you look for the errors (highlighted in red) in the activity pane (left), then zero in on the action which failed (top right pane) and in the details section (bottom right pane), there will be a description of the inner exception which is being thrown, which almost always tells you what the exception which is being thrown is and give you more information about how to resolve it.

<system.diagnostics>
  <sources>
     <source propagateActivity="true" name="System.ServiceModel" switchValue="Information, ActivityTracing">
        <listeners>
           <add name="ServiceModelMessageLoggingListener">
              <filter type="" />
           </add>
        </listeners>
     </source>
     <source name="System.ServiceModel.MessageLogging" switchValue="Warning,ActivityTracing">
        <listeners>
           <add name="ServiceModelMessageLoggingListener">
              <filter type="" />
           </add>
        </listeners>
     </source>
  </sources>
  <sharedListeners>
     <add initializeData="C:\temp\WCFLogs\ServerWCFTraces.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
        <filter type="" />
     </add>
  </sharedListeners>
</system.diagnostics>

这篇关于WCF服务 - 未能调用服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆