I have designed a small WCF WebService. While I am trying to access its methods from the client; some are able to access but some are not. I am putting piece of code below:
[System.ServiceModel.ServiceBehaviorAttribute(InstanceContextMode=System.ServiceModel.InstanceContextMode.PerCall, ConcurrencyMode=System.ServiceModel.ConcurrencyMode.Single)]
public class RestuarantService : IRestuarantService
{
public virtual GetRestaurantsResponse GetRestaurants(GetRestaurantsRequest request)
{
throw new System.NotImplementedException();
}
public virtual void AddRestaurant(AddRestaurant request)
{
throw new System.NotImplementedException();
}
public virtual void RateRestaurant(RateRestaurant request)
{
throw new System.NotImplementedException();
}
}
From the above piece of code I am not able to access GetRestaurants() method from client. Couldnt understand the reason for this. Can anyone please help me in this.
Wherever you have GetRestaurantsResponse defined, is the class annotated with a [DataContract] attribute and the properties annotated with a [DataMember] attribute?
For example:
[DataContract]
publicclass PurchaseOrder
{
privateint poId_value;
// Apply the DataMemberAttribute to the property.
[DataMember]
publicint PurchaseOrderId
{
get { return poId_value; }
set { poId_value = value; }
}
}
Without that, the call won't work because WCF will not understand the return type.
Darrell Norton, MVP
Darrell Norton's Blog Please click "Mark as Answer" if this helped you.
Afreen_IT
Member
30 Points
67 Posts
Client not able to access some methods of WCF Service
Feb 03, 2012 04:11 AM|LINK
Hi,
I have designed a small WCF WebService. While I am trying to access its methods from the client; some are able to access but some are not. I am putting piece of code below:
[System.ServiceModel.ServiceBehaviorAttribute(InstanceContextMode=System.ServiceModel.InstanceContextMode.PerCall, ConcurrencyMode=System.ServiceModel.ConcurrencyMode.Single)]
public class RestuarantService : IRestuarantService
{
public virtual GetRestaurantsResponse GetRestaurants(GetRestaurantsRequest request)
{
throw new System.NotImplementedException();
}
public virtual void AddRestaurant(AddRestaurant request)
{
throw new System.NotImplementedException();
}
public virtual void RateRestaurant(RateRestaurant request)
{
throw new System.NotImplementedException();
}
}
From the above piece of code I am not able to access GetRestaurants() method from client. Couldnt understand the reason for this. Can anyone please help me in this.
Thanks & regards,
Afreen
DarrellNorto...
All-Star
87485 Points
9724 Posts
Moderator
MVP
Re: Client not able to access some methods of WCF Service
Feb 03, 2012 10:33 AM|LINK
Wherever you have GetRestaurantsResponse defined, is the class annotated with a [DataContract] attribute and the properties annotated with a [DataMember] attribute?
For example:
[DataContract] public class PurchaseOrder { private int poId_value; // Apply the DataMemberAttribute to the property. [DataMember] public int PurchaseOrderId { get { return poId_value; } set { poId_value = value; } } }Without that, the call won't work because WCF will not understand the return type.
Darrell Norton's Blog
Please click "Mark as Answer" if this helped you.
ramanselva
Contributor
2064 Points
324 Posts
Re: Client not able to access some methods of WCF Service
Feb 03, 2012 10:41 AM|LINK
Hi,
Please make sure that GetRestaurants marked as [OperationContract] attribute and GetRestaurantsRequest & GetRestaurantsResponse
marked as [DataContract] attribute. Meanwhile you can also check your .svc?wsdl file wherther the type GetRestaurants exposed and also
try with re-creating service reference from your client.
This can be beneficial to other community members reading the thread.
Regards,
Rama Selvam M.