WCF and ef 4.0 performance is very bad .... Site works very slow - wcf

we have a project in which we have used WCF because we have multiple sites which pull up the same data .... We have used HTTPBinding in WCF and EF 4.0 to interact with the database .. When it was moved to production environment we found that the site was very slow .... Do you know any way how we could increase the performance drastically ... EF is causing a lot performance issues ... Please suggest next steps
Service Contract
[ServiceContract]
public interface ICommonService
{
[OperationContract]
LoginDTO AuthenticateUser(string userName, string password, int ownerId);
}
<service name="MyService.Services.CommonService">
<endpoint binding="basicHttpBinding" bindingConfiguration=""
name="CommonServiceEndpoint" contract="MyService.Services.Contracts.ICommonService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/MyService.Services/ICommonService/" />
</baseAddresses>
</host>
</service>
We have introduced indexing but it doesn't increase performance so much
using (MyService.DataAccess.MyService_RedesignEntities context = new MyService_RedesignEntities())
{
context.ContextOptions.ProxyCreationEnabled = false;
context.ContextOptions.LazyLoadingEnabled = false;
ObjectParameter StrOutput = new ObjectParameter("chvnOutputMesage", SqlDbType.NVarChar);
objResult = context.spAuthenticateUser(ownerId, userName, encryptedPassword).FirstOrDefault();
return objResult;
}

Related

WCF service hangs when calling method, however method is working

Hello I'm having issue with my wcf service. I'm trying to call method which returns list of type object. I'm also using entity framework.
public IList<Product> GetAllProducts()
{
using (var db = new AuctionContext())
{
return db.Products.ToList();
}
}
</service>
<service name="AuctionSystem.WcfService.ProductService">
<endpoint address="" binding="wsDualHttpBinding" contract="AuctionSystem.WcfService.Contracts.IProductService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:9993/Design_Time_Addresses/AuctionSystem.WcfService/ProductService/" />
</baseAddresses>
</host>
</service>
And contract :
[OperationContract]
IList<Product> GetAllProducts();
The method itself is working, but when I try to invoke this method on my wcf service UI it got stuck at "invoking service" I'm using wsdualhttpbinding.
Any ideas please?
EDIT: I realized in Product object I have virtual List, why is this List causing wcf to hang?
For all wondering why It was caused because of circular dependency.

WCF Web Service Hosted in SharePoint 2010 browser blank page response

I'm facing a problem with SharePoint 2010 custom web service.
The service is an SVC installed and deployed on the system: without particular configuration it works but I need to customize the web.config to achieve some security roles.
The problems is that when I try to invoke methods from browser the response is empty.
This is my web.config
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="SharePointWCFService.GetListData"
behaviorConfiguration="WCFBasicHttpBinding.Service1Behavior">
<endpoint address="http://address" binding="basicHttpBinding" contract="SharePointWCFService.IGetListData">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="http://address" binding="WebHttpBinding" contract="SharePointWCFService.IGetListData" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WCFBasicHttpBinding.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
This is the interface I'm implementing:
[ServiceContract]
public interface IGetListData
{
[OperationContract]
[WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
JSonResult GetJsonResponse(string data);
}
And this the class
[BasicHttpBindingServiceMetadataExchangeEndpointAttribute]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
class GetListData : IGetListData
{
private const string Admin_Svc_GetListData = "Admin_Svc_GetListData";
public JSonResult GetJsonResponse(string data)
{
return new JSonResult()
{
Firstname = "MyFirstname",
Lastname = "MyLastname"
};
} // public JSonResult GetJsonResponse(string data)
Do I must declare something different at web.config side?

how to bind endpoints?

although there are many posts about the same issue I still haven't figured out how to solve the problem regarding endpoints.
In the solution there are several projects and after reading about similar problems I edited the app.config file of the StartUp Project the following way:
<system.serviceModel>
<services>
...
<service name="LiveGames.Engine.LoginService">
<endpoint address="" name="ILoginService" binding="wsHttpBinding" contract="LiveGames.Entities.Interfaces.ILoginService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/LiveGames.Engine/LoginService/" />
</baseAddresses>
</host>
</service>
</services>
<client>
<endpoint address="http://localhost:8732/LiveGames.Engine/LoginService/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_ILoginService" contract="LiveGames.Entities.Interfaces.ILoginService"
name="ILoginService" kind="" endpointConfiguration="">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
I created the Proxy class with the following methods:
public ChannelFactory<T> GetFactory<T>(string serviceName, out T channel)
{
ChannelFactory<T> factory = new ChannelFactory<T>(serviceName);
channel = factory.CreateChannel();
return factory;
}
public JSONUserLogin Login(string username, string password)
{
JSONUserLogin retval = new JSONUserLogin();
ILoginService sec = null;
ChannelFactory<ILoginService> factory = null;
try
{
using (factory = GetFactory<ILoginService>("ILoginService", out sec))
{
retval = sec.Login(username, password);
}
return retval;
}
catch (Exception ex)
{
return new JSONUserLogin();
}
finally
{
if (sec != null)
((IChannel)sec).Close();
if (factory != null)
factory.Close();
}
}
When serviceName="ILoginService" and the execution hits the line ChannelFactory<T> factory = new ChannelFactory<T>(serviceName);
it throws an exception:
System.InvalidOperationException: Could not find endpoint element with name 'ILoginService' and contract 'LiveGames.Entities.Interfaces.ILoginService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.
Does anyone know what could be wrong here and how to fix the problem?

wcf service hosted under IIS address

I have a WCF service hosted under IIS.
I have the following configuration:
<services>
<service name="BillboardServices.LoginService" behaviorConfiguration="LoginServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://myip/LoginService/" />
</baseAddresses>
</host>
<endpoint address="" name="LoginService" binding="basicHttpBinding" contract="BillboardServices.ILoginService" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
If I enter http://myip/LoginService/, I get a 404.
If I enter http://myip/Service1.svc, I get the service metadata.
What changes to the configuration do I need in order for the service to be accessible through the nice url?
Thank you.
In order to have and extensionless service, you need to use WCF 4 and init the routing engine in the global.asax file like so:
void Application_Start(object sender, EventArgs e)
{
RegisterRoutes();
}
private void RegisterRoutes()
{
// Edit the base address of Service1 by replacing the "Service1" string below
RouteTable.Routes.Add(new ServiceRoute("Service1", new WebServiceHostFactory(), typeof(Service1)));
}

same app.config : wcftestclient work, selfHosting doesnot

i have the same app config on both programs
A - the service itself when i run it , wcf Test Client starts.
B - A self host program using -new ServiceHost(typeof(MyService)))
here it is :
<services>
<service name="MyNameSpace.MyService"
behaviorConfiguration="MyService.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:5999/MyService"/>
</baseAddresses>
</host>
<endpoint
binding="basicHttpBinding"
contract="StorageServiceInterface.IService1"
bindingConfiguration="MyBasicHttpBinding"
name="basicEndPoint">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="MyBasicHttpBinding">
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="HeziService.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
the client Uses ClientBase<StorageServiceInterface.IService1>
Client app.config :
<system.serviceModel>
<client>
<endpoint address="http://myIp/MyService"
binding="basicHttpBinding"
contract="StorageServiceInterface.IService1">
</endpoint>
</client>
</system.serviceModel>
when i run the selfhost program and doing host.open()
it does open it, but when i try to call a method it tells me that :
"No connection could be made because the target machine actively refused it 10.0.0.1:5999"
ofcourse when the service run from the WCF Test Client, every thing working.
how could it be ??
thanks in advance
Just guessing - how about adding an address to your server side endpoint:
<endpoint address="" .... >
Yes, the base address basically defines the whole address - but you should still add the address to your service endpoint - even if it's empty.
something strange:
regards to marc_s that ask me to write my selfhost prog code..
i was using :
private void m_startServiceToolStripMenuItem_Click(object sender, EventArgs e)
{
using (Host = new ServiceHost(typeof(MyNameSpace.MyService)))
{
Host.Open();
}
}
before i've added it to the question i tried to change it without the using part :
private void m_startServiceToolStripMenuItem_Click(object sender, EventArgs e)
{
Host = new ServiceHost(typeof(yNameSpace.MyService));
Host.Open();
}
and now its working !!
but, somehow it worked before...
thank you all anyway :-)