问题
Ufuk Hacıoğulları wrote a nice WCF helper class called WcfClientBase. However I've had some difficulty in implementing it.
I defined my class as follows:
public class ModelsBaseClass : ServiceClientBase<MemberServiceClient>
{...
And attempting to use the helper class in the following method that returns a complex object through Entity Framework:
public static MyProject.DAL.Primary.Models.sq_newsfeed_GetProfileByID_Result GetAllProfileDetails(int profileID)
{
try
{
using (memberServiceClient = new MemberServiceClient()) // connect to the data service
{
return memberServiceClient.GetAllProfileDetailsByID(profileID);
}
}
catch (Exception ex)
{
ErrorLogging.Instance.Fatal(ex);
return null;
}
}
Following the examples here, I am unable to access the class' methods even though this is a derived class, and the protected
access modifier should allow access - right?
Basically I cannot access the PerformServiceOperation
or TryPerformServiceOperation
methods in my model base class.
回答1:
Did you notice your method is static
? That's the reason you cannot access instance members of the parent class.
来源:https://stackoverflow.com/questions/11435245/how-to-use-the-wcfclientbase-helper-class-for-wcf-connections