开发者

WCF service method returning null

I have a WCF service and when i call it the string is coming back null and i cant figure out why!

this is the calling code:

new Thread(() =>
            {
                string returned = _client.Service.GetString();
                this.Dispatcher.BeginInvoke((Action)(() => MessageBox.Show(returned)));
            }).Start();

This is the service implementation:

    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
class MyService: ServiceBase, IMyService
{
    public string GetString()
    {
        return "Returned";
    }

And this is the Interface:

    [ServiceContract]
public interface IMyService: IServiceBase
{
    [OperationContract]
    string GetString();
}

The calling code is just coming back with 开发者_运维问答null but the client is connecting to the service fine, am I missing something?


If you haven't already you can configure tracing for WCF and get a lot out of the log files. Not knowing exactly what the config looks like or how _client is built I can't say what is wrong. The code that you have posted here looks like it should work fine.

<configuration>
   <system.diagnostics>
      <sources>
            <source name="System.ServiceModel" 
                    switchValue="Information, ActivityTracing"
                    propagateActivity="true">
            <listeners>
               <add name="traceListener" 
                   type="System.Diagnostics.XmlWriterTraceListener" 
                   initializeData= "WcfTraces.svclog" />
            </listeners>
         </source>
      </sources>
   </system.diagnostics>
</configuration>

Adding this to your app.config or web.config will create a WcfTraces.svclog file in the same directory as the config file with all kinds of data. You should be able to just double click the log file to open it with the Microsoft Service Trace Viewer.

Configure WCF Tracing

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜