Solved

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

Posted on 2012-03-19
16
5,710 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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
 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!

751 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