WCF调用服务失败WCF

2023-09-04 04:31:59 作者:妳並不難懂\

我会能够调用它在我自己的服务器和它的作品,但是当我在IIS托管WCF服务出现问题。错误的细节下面...

  

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

     

堆栈跟踪错误详细信息

     

服务器无法处理请求由于内部错误。   有关错误的详细信息,无论是打开   IncludeExceptionDetailInFaults(无论是从ServiceBehaviorAttribute   或从< serviceDebug> 配置行为)在服务器上   为了发送异常信息返回给客户端,或打开   跟踪按在Microsoft .NET Framework 3.0 SDK文档和   检查服务器跟踪日志。

     

服务器堆栈跟踪:   在System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(消息   回复,MessageFault故障,串动,MessageVersion版本,   FaultConverter faultConverter)   在System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime   操作,ProxyRpc和放大器; RPC)   在System.ServiceModel.Channels.ServiceChannel.Call(串动,   布尔单向,ProxyOperationRuntime操作,对象[]插件,   [对象]出局,时间跨度超时)   在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage   methodCall,ProxyOperationRuntime操作)   在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(即时聊天   消息)

     

例外重新抛出的[0]:   在System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(即时聊天   reqMsg,即时聊天retMsg)   在System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&安培;   MSGDATA,的Int32型)   在IUserService.GetUser(字符串用户名)   在UserServiceClient.GetUser(字符串userid)

下面是源$ C ​​$ CS:

从wcfservicelirbrary app.config文件

 < XML版本=1.0编码=UTF-8&GT?;
<结构>

<的System.Web>
<编译调试=真/>
< /system.web>
  < system.serviceModel>
    <服务>
      <服务名称=UserServiceLibrary.UserService>
        <端点地址=绑定=的wsHttpBinding合同=UserServiceLibrary.IUserService>
          <身份>
            < D​​NS值=本地主机/>
          < /身分>
        < /端点>
        <端点地址=MEX绑定=mexHttpBinding合同=IMetadataExchange接口/>
        <主机>
          < baseAddresses>
            <新增baseAddress =HTTP://本地主机:8732 / Design_Time_Addresses / UserServiceLibrary / UserService的//>
          < / baseAddresses>
        < /主机>
      < /服务>
    < /服务>
    <行为>
      < serviceBehaviors>
        <行为>
          < serviceMetadata httpGetEnabled =真/>
          < serviceDebug includeExceptionDetailInFaults =FALSE/>
        < /行为>
      < / serviceBehaviors>
    < /行为>
  < /system.serviceModel>
< /结构>
 
学习 WCF 6 学习调用WCF服务的各种方法

从WCF网站主机的Web配置文件

 < XML版本=1.0&GT?;
 <结构>

  <的System.Web>
    <编译调试=假targetFramework =4.0/>
  < /system.web>
  < system.serviceModel>
    <服务>
      <服务名称=UserServiceLibrary.UserService>
       <端点地址=MEX绑定=mexHttpBindingbindingConfiguration =
  合同=IMetadataExchange接口/>
       <端点地址=基本的绑定=basicHttpBinding的bindingConfiguration =
  合同=UserServiceLibrary.IUserService/>
       <端点地址=绑定=的wsHttpBinding合同=UserServiceLibrary.IUserService/>
      < /服务>
    < /服务>
    <行为>
     < serviceBehaviors>
       <行为>

         < serviceMetadata httpGetEnabled =真/>

          < serviceDebug includeExceptionDetailInFaults =FALSE/>
       < /行为>
      < / serviceBehaviors>
    < /行为>
    < serviceHostingEnvironment multipleSiteBindingsEnabled =真/>
< /system.serviceModel>
< system.webServer>
   <模块runAllManagedModulesForAllRequests =真/>
< /system.webServer>
< /结构>
 

解决方案

确保帐户下运行的过程,其中承载服务具有访问权限的数据库。例如如果IIS帐户运行该服务托管必须登陆到数据库服务器,它必须有权做一切必要的业务数据库中的应用程序池。

I could be able to call it in my own server and it works but the problem occurs when I host wcf service in IIS. The details of the error are the following...

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.

Stack Trace Error Details

The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.

Server stack trace: at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter) at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) 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 IUserService.GetUser(String UserID) at UserServiceClient.GetUser(String UserID)

Here are the source codes:

app.config file from wcfservicelirbrary

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<system.web>
<compilation debug="true" />
</system.web>
  <system.serviceModel>
    <services>
      <service name="UserServiceLibrary.UserService">
        <endpoint address="" binding="wsHttpBinding"      contract="UserServiceLibrary.IUserService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8732/Design_Time_Addresses/UserServiceLibrary/UserService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>        
</configuration>

Web config file from WCF Website Host

<?xml version="1.0"?>
 <configuration>

  <system.web>
    <compilation debug="false" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="UserServiceLibrary.UserService">
       <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
  contract="IMetadataExchange" />
       <endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
  contract="UserServiceLibrary.IUserService" />
       <endpoint address="" binding="wsHttpBinding" contract="UserServiceLibrary.IUserService" />
      </service>
    </services>
    <behaviors>
     <serviceBehaviors>
       <behavior>

         <serviceMetadata httpGetEnabled="true"/>

          <serviceDebug includeExceptionDetailInFaults="false"/>
       </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
   <modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>  
</configuration>

解决方案

Ensure that account running your process where the service is hosted has access rights to the database. For example in case of IIS the account running the application pool where the service is hosted must have login to database server and it must have permissions to do all necessary operations in your database.