0

我有一个使用对类库的引用的 WCF 服务。该库中的类执行与数据库交互之类的操作。我正在通过浏览器使用 restful 调用测试我的服务(编译时没有错误),它只显示一个页面,上面只显示“找不到端点。”。我假设这与库引用连接字符串和应用程序设置等(我通常必须包含在使用该库的应用程序中)的事实有关。所以我很难找到的是如何正确配置 wcf 服务以使用这个库。我尝试简单地将连接字符串和应用程序设置添加到 wcf web.config,但这似乎没有帮助。我觉得这只是通过服务的端点部分添加对库的引用。但我迷路了。任何帮助表示赞赏。谢谢

<system.serviceModel>
    <services>
      <service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehavior">
        <endpoint address="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web">

        </endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name ="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

更新:运行跟踪,这是抛出异常的堆栈跟踪:

System.ServiceModel.Dispatcher.HttpUnhandledOperationInvoker.Invoke(对象实例,对象 [] 输入,对象 []& 输出) System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) System.ServiceModel.Dispatcher.ImmutableDispatchRuntime。ProcessMessage11(MessageRpc& rpc) System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet) System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext) System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext) System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult 结果) System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult 结果) System.Runtime.Fx.AsyncThunk。 UnhandledExceptionFrame(IAsyncResult 结果) System.Runtime.AsyncResult.Complete(布尔完成同步) System.Runtime.InputQueueServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet) System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext) System.ServiceModel.Dispatcher.ChannelHandler .HandleRequest(RequestContext request, OperationContext currentOperationContext) System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult 结果) System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult 结果) System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult 结果) 系统。 Runtime.AsyncResult.Complete(Boolean completedSynchronously) System.Runtime.InputQueueServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet) System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext) System.ServiceModel.Dispatcher.ChannelHandler .HandleRequest(RequestContext request, OperationContext currentOperationContext) System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult 结果) System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult 结果) System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult 结果) 系统。 Runtime.AsyncResult.Complete(Boolean completedSynchronously) System.Runtime.InputQueuerpc) System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet) System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext) System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext) System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult 结果) System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult 结果) System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult 结果) System.Runtime.AsyncResult.Complete(布尔完成同步) System.Runtime.InputQueuerpc) System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet) System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext) System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext) System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult 结果) System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult 结果) System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult 结果) System.Runtime.AsyncResult.Complete(布尔完成同步) System.Runtime.InputQueueDispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext) System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext) System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult 结果) System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete( IAsyncResult 结果) System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult 结果) System.Runtime.AsyncResult.Complete(布尔完成同步) System.Runtime.InputQueueDispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext) System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext) System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult 结果) System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete( IAsyncResult 结果) System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult 结果) System.Runtime.AsyncResult.Complete(布尔完成同步) System.Runtime.InputQueueAsyncMessagePump(IAsyncResult 结果) System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult 结果) System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult 结果) System.Runtime.AsyncResult.Complete(布尔完成同步) System.Runtime.InputQueueAsyncMessagePump(IAsyncResult 结果) System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult 结果) System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult 结果) System.Runtime.AsyncResult.Complete(布尔完成同步) System.Runtime.InputQueue1.AsyncQueueReader.Set(Item item) System.Runtime.InputQueue1.EnqueueAndDispatch(Ite​​m item, Boolean canDispatchOnThisThread) System.Runtime.InputQueue1.EnqueueAndDispatch(T item, Action dequeuedCallback, Boolean canDispatchOnThisThread) System.ServiceModel.Channels.SingletonChannelAcceptor3.Enqueue(QueueItemType item, Action dequeuedCallback, Boolean canDispatchOnThisThread) System.ServiceModel.Channels.HttpChannelListener.HttpContextReceived(HttpRequestContext context, Action回调) System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult结果) System.ServiceModel.Activation.HostedHttpRequestAsyncResult。 HandleRequest() System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest() System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(对象状态) System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) System.Runtime .Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 错误,UInt32 bytesRead,NativeOverlapped* nativeOverlapped) System.Threading._IOCompletionCallback。PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

4

1 回答 1

0

好的,所以我让它工作了。似乎是主机地址的问题。我将项目重新创建为服务库而不是服务应用程序,我注意到默认配置中有几个新字段。其中之一是给主人的。当我设置基地址时,一切都开始工作了。这是配置:

<system.serviceModel>
<services>
  <service name="ServiceWithLibraryTest.UtiService">
    <endpoint address="" binding="webHttpBinding" contract="ServiceWithLibraryTest.IUtiService" behaviorConfiguration="web" />        
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8732/ServiceWithLibraryTest/UtiService/"/>
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="False"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>

我对 WCF 有点陌生,据我了解,配置经常令人头疼是臭名昭著的。我仍在努力研究端点,但我开始更好地理解端点如何只是暴露服务和行为的方式,即它们是如何通信的。然后,当然,休息服务为其添加了一个全新的层。我很欣赏这些想法:)

于 2012-09-04T15:43:32.157 回答