Solved

C# - WCF - "Failed to Invoke The Service"

Posted on 2012-03-19
16
5,336 Views
Last Modified: 2012-06-27
I received the error in the title.  Can someone help me troubleshoot?

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 ITransferService.GetData(Int32 value)
   at TransferServiceClient.GetData(Int32 value)

*********************************************************

Here is the code

    [ServiceContract]
    public interface ITransferService
    {
       [OperationContract]
        string GetData(int value);
    }

    [Serializable]
    public class TransferService : ITransferService
    {
        public string GetData(int value)
        {
            return value.ToString();
        }
    }
0
Comment
Question by:CipherIS
  • 8
  • 7
16 Comments
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 37740758
how are u hosting ur service , if it's in iis /webdev then try opening the svc file thru browser and see whats happening
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37741009
Remove [Serializable] attribute from implementation and add service behaviour with exception details in faults turned on as:-

    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class TransferService : ITransferService
    {
        public string GetData(int value)
        {
            return value.ToString();
        }
    }

Next on client try to invoke the service under try/catch block and see the exception that you get.
0
 
LVL 1

Author Comment

by:CipherIS
ID: 37742680
@BuggyCoder - I implemented the changes you suggested.  This is the error I am receiving with the Try/Catch - Object reference not set to an instance of an object.

Some Info.  

I when I view the Transfer.svc in Browswer the web page comes up and gives me the URL with the ?wsdl.

I have two websites.

1.  ASP.NET website with add Service Reference using http://blahblahblah/transfer.svc
2.  ASP.NET webiste with add Service Reference using discovery (localhost)

When testing the ASP.NET website that is calling the WCF using localhost I have no issues.
When testing the ASP.NET website using http I am receiving this error.

Also, I run the WCFTestClient an enter the endpoint address:  http://XXX.XXX.XXX.XXX/APIHost/Transfer.svc I can see all the methods that are in the WCF app.  I click on Get Data and enter a value "5" and click on Invoke then I get the below error:

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.
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37742896
the error means that your are trying to access a disposed object on server side.
Try to debug the service and see where the error is, Fixing the error on server side will fix your issue definitely....

also make sure that all the service side code is handled for exceptions....
0
 
LVL 1

Author Comment

by:CipherIS
ID: 37743056
Can't debug the service when adding it with http://xxx.xxx.xxx.xxx./transfer.svc.

I debug with http://localhost:xxxx/transfer.svc - I can debug and there are no issues at all.  I put code i the WCF to write to a text file and text file is not creatd at all.
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37743438
please share the code for svc method that you are calling.
I hope there is try catch block on your svc method that you are calling...
0
 
LVL 1

Author Comment

by:CipherIS
ID: 37744065
Here is my WCF code.

namespace TransferService
{
    [ServiceContract]
    public interface ITransferService
    {
       [OperationContract]
        string GetData(int value);
    }
}

namespace TransferService
{
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class TransferService : ITransferService
    {

        //For Testing Purposes
        public string GetData(int value)
        {
            try
            {
                return value.ToString();
            }
            catch (Exception ex)
            {
                return = ex.Message.ToString();
           }
        }
}
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37744123
this looks fine, let me know how are you calling it from client, which binding etc.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 1

Author Comment

by:CipherIS
ID: 37744155
Here is a portion of the web.config

   <basicHttpBinding>
    <binding name="BasicHttpBinding_ITransferService"
              closeTimeout="04:01:00" openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00"
              allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
              maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
              messageEncoding="Text" textEncoding="utf-8" transferMode="StreamedRequest"
              useDefaultWebProxy="true">
    <readerQuotas maxDepth="2147483647"
                  maxStringContentLength="2147483647"
                  maxArrayLength="2147483647"
                  maxBytesPerRead="2147483647"
                  maxNameTableCharCount="2147483647"/>
     <security mode="None">
      <transport clientCredentialType="None" proxyCredentialType="None"
       realm="" />
      <message clientCredentialType="UserName" algorithmSuite="Default" />
     </security>
    </binding>
   </basicHttpBinding>
  </bindings>
            <client>
   <endpoint address="http://1xxx.xxx.xxx.xxx/APIFulfillmentHost/Transfer.svc/basic"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ITransferService"
    contract="MDRTransferServiceReference.ITransferService" name="BasicHttpBinding_ITransferService" />
  </client>
      </system.serviceModel>
0
 
LVL 1

Author Comment

by:CipherIS
ID: 37744160
Here is code on client

            ITransferService Test= new ransferServiceClient();
           string s = Test.GetData(5);

Above code works when I do Add Service Reference Discover but when I actualy type the http://xxx.xxx.xxx.xxx/Transfer.svc it finds my WCF Service but the code above blows up.
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37744252
How are you hosting this service, inside IIS or is self hosted.
Because if it is self hosted, then you have to use netsh to add the address to allowed set of addresses...
0
 
LVL 1

Author Comment

by:CipherIS
ID: 37744362
Inside IIS 7
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37744369
are you still getting object reference not set to an instance of object error....
0
 
LVL 1

Author Comment

by:CipherIS
ID: 37744428
yes - only when I bind it via Add Service Reference and type the URL and click on GO.  

If I use discover and bind it via localhost - no.
0
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37744481
0
 
LVL 1

Author Comment

by:CipherIS
ID: 37744604
Well - I have a solution.  I created a new WCF service and hosted it.  I am able to connect to that Service via IP and its working.  The original is not.  Don't know y the original works with everything else but IP.  So I will move my changes to the new one

Thanks for your help.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now