1

I have a simple WCF logging service..

namespace WCFServiceLibrary
{
    [ServiceContract]
    public interface ILog
    {
        [OperationContract]
        string InsertLogItem(LogItem logItem);
    }

    [DataContract]
    public class LogItem
    {
        private string _Text = string.Empty;

        [DataMember]
        public string Text
        {
            get { return _Text; }
            set { _Text = value; }
        }
    }
}

And I have a client, and a DLL, all in the same solution.

If I reference the service from the Client, I can see the DataContract. If I reference the service from the DLL, I can NOT see the DataContract.

By which I mean that it I reference the service as LogService, and have this code in the client...

static LogService.LogClient logService = new LogService.LogClient();
//create log item - <<< Compile error in DLL on following line >>>
var itemTolog = new LogService.LogItem { Text = "log this"}; 
string result = logService.InsertLogItem(itemTolog);

then it works fine, but if the same code is in the DLL, then it will not compile due to LogService.LogItem not being visible, and reports the following error

The type or namespace name 'LogItem' does not exist in the namespace 'MyDll.LogService' (are you missing an assembly reference?)    

The dataContract "LogItem" is simply not in the object explorer when the service is referenced from the dll, but it is if referenced from the client exe.

What gives? Needless to say I want to reference the Service from the DLL. I've read elsewhere that you can only see the data contract if it is actively used in one of the service contracts, but it is.

4

1 回答 1

1

OK. I've fixed this by:

  • right clicking on the service reference in the DLL
  • clicked ‘Configure Service Reference...’</li>
  • unchecked "Resuse types in referenced assemblies".

tbh I do not know why this works, but it does... [gaelic shrug]

于 2012-11-09T14:17:29.977 回答