4
votes

I was 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 this error are as follows...

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:

  1. 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>
    
  2. 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>
    
4
First, go to the server and apply the following configuration updates: msdn.microsoft.com/en-us/library/…dotnetnate
Also take a look at UserServiceClient.GetUser(String UserID) - that's where the exception originally occurred. Post your code and any additional information you get from dotnetnate's suggestion for better answers :)Tim
Above are the source codes of my configuration. Please check it. thz.user851449

4 Answers

2
votes

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.

1
votes

As usual with WCF errors, the key is most likely right at the bottom of the stack trace:

UserServiceClient.GetUser(String UserID)

This was what caused the error in the first place.

To check, if you have access to the server, try attaching a Visual Studio debugger to the IIS service (usually w3wp.exe) that hosts your WCF code. (Do this though Debug | Attach to Process...; you'll need be running with Administrator privileges, and check "on" the "View processes from all users" option).

If you don't have direct access to attach a debugger to the service but can tweak the configuration file for the service, then try the WCF diagnostic traces (documented on MSDN here). This lets you create logs that can be viewed with the Service Trace Viewer - you should be able to find much more information on the exception very easily using this.

A hunch: is UserID null, by any chance? If so, and you're not expecting it to be, has the service contract changed recently? Adding System.Runtime.Serialization to the diagnostic trace for the Service Viewer can bring up some more information on that: details here.

0
votes

Best practices with WCF,

  1. Make sure WCF project url along with Virtual directory is showing up without errors, and could generate proxy ( svcutil followed by hyperlink)

2 Once WCF is fine, in Client project, In ServiceReferences, choose CONFIGURE services with this above URL, 3. That should generate proxy, if its attached to source control like TFS, please make sure to check in - delete mode checkins also, ALONG with newly generated files ( show hidden files in the project)

  1. Click on Reference.cs --> do a acid test to verify your new datacontract or datamember fields are generated, that confirms service is Upto Date

All those nasty WCF references error tough to solve, but regenerating may give relief some times...

0
votes

Problem :- I had the same problem with hosted WCF service on one of our windows servers. Application was unable to connect with the service.

Solution :- Had to reset app/pool of WCF service

Thanks