Jithendra
Jithendra

Reputation: 351

WCF service shutting down

i have been trying to access WCF service function(Which loads C++ Dll's too) in a C# client project.

When ever i start client program it fetches the service, loads the dll, but suddenly WCF service will be terminated from the system tray.

I have added timeout parameters in web.config(Service) and app.config(Client).

i have tried to log the error as said here but still its not logging the errors.

what's causing this error, any help will be appreciated.

Update 1 Here's my trace.svclog

Update 2 Here's my entire Code This contains 2 solutions, HelloWorld is a C++ Dll & WcfServices Contains both server(C++ Dll'll be loaded) and Client Projects. These projects have all the changes made till now based on internet solutions.

Regards, Jithendra

Upvotes: 0

Views: 900

Answers (3)

Jithendra
Jithendra

Reputation: 351

Both the above answer by me as well by @Giorgi Nakeuri were right, but when i installed the WCF service as a stand alone service and tried to run the client it again started throwing the same exception.

i use Visual studio 2013 and in .Net 4.5 loading normal unmanaged c++ library into C# is throwing an error(I don't know exactly why), Here's what i did to make it stable.

  1. i converted unmanaged c++ library into managed c++ interop library(Which supports CLR functionalities).
  2. in the same way i have accessed them in C#.

these changes working like charm and much stable.

Hope this improved answer helps someone.

Upvotes: 0

Giorgi Nakeuri
Giorgi Nakeuri

Reputation: 35780

Add the following to your hoster Web.Config. After crash open C:\Trace.svclog and look on red line. Look at XML tab and you will see details about error.

<system.diagnostics>
    <sources>
      <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
        <listeners>
          <add name='traceListener' type='System.Diagnostics.XmlWriterTraceListener' initializeData='C:\Trace.svclog'/>
        </listeners>
      </source>
    </sources>
</system.diagnostics>

Ohhh man, finally i get it to work. What you should do is

[DllImport(@"C:\...\Helloworld.dll", CharSet = CharSet.Ansi, EntryPoint = "Encode01", ExactSpelling = false, SetLastError = true, CallingConvention = CallingConvention.Cdecl)]

[return: MarshalAs(UnmanagedType.SysInt)]
public static extern IntPtr Encode01();

and

 public string Genkey()
 {
     IntPtr ptr = Encode01();
     return Marshal.PtrToStringAnsi(ptr);
 }

Upvotes: 3

Jithendra
Jithendra

Reputation: 351

My problem was in c++ Dll not in WCFService which i was loading in WCF Service. As per this Link explanation, i was doing

this

char* pszReturn = new char[256];

instead of this

char* pszReturn = NULL;
pszReturn = (char*)::CoTaskMemAlloc(ulSize);

this was causing error in returning the value, and in result below exception was thrown.

Content Type application/soap+xml; charset=utf-8 was sent to a service expectingtext/xml; charset=utf-8. The client and service bindings may be mismatched.

Hope it helps somebody and Special Thanks for @Giorgi Nakeuri for leading me to this.

Regards,

Jithendra.

Upvotes: 1

Related Questions