How do I set dns programmatically like doing for other configuration as below?
<endpoint address="https://admin.icafems.com/Services/EasyStartTrackingService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IEasyStartTrackingService"
contract="ES_Service.IEasyStartTrackingService" name="WSHttpBinding_IEasyStartTrackingService">
<identity>
<dns value="admin.icafems.com" />
</identity>
</endpoint>
ServiceClient.Endpoint.Address = new EndpointAddress(ServiceURL);
ServiceClient.Endpoint.Binding = binding;
ServiceClient.Endpoint.Name = "BasicHttpBinding_ILearningSuiteService";
You pass an EndpointIdentity to the constructor of the EndpointAddress
http://msdn.microsoft.com/en-us/library/bb628618.aspx
Related
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.
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?
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?
I'm getting this
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
when trying to access the service from my browser. Here is my config.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<!-- Note: the service name must match the configuration name for the service implementation. -->
<service name="WcfServiceLibrary.Service1" behaviorConfiguration="MyServiceTypeBehaviors" >
<!-- Add the following endpoint. -->
<!-- Note: your service must have an http base address to add this endpoint. -->
<endpoint contract="WcfServiceLibrary.Service1" binding="basicHttpBinding" address="http://localhost/service1" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="http://localhost/service1/mex" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors" >
<!-- Add the following element to your service behavior configuration. -->
<serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost/service1" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
When I type http://localhost/service1 in the web browser I get the 404. But if I remove the app.config below and just simpley do this in the code behind
string serviceUrl = "http://localhost/service1";
Uri uri = new Uri(serviceUrl);
host = new ServiceHost(typeof(Service1), uri);
host.Open();
All works well... Any ideas? Seems simple enough.
I think you are missing the host element under your services:
<service name="WcfServiceLibrary2.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://localhost/service1" />
</baseAddresses>
</host>
<endpoint address ="" binding="wsHttpBinding" contract="WcfServiceLibrary2.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
Service host does not need URL then.
static void Main(string[] args)
{
var host = new ServiceHost(typeof(Service1));
host.Open();
Console.WriteLine("Host running");
Console.ReadLine();
}
You can show http://localhost/service1?Wsdl in the browser but mex only works with add service reference or WCFTestClient (C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE) because you will get the HTTP Bad Request error which comes from the fact that the browser issues an HTTP GET request where the contents of the message are in the HTTP headers, and the body is empty.
This is exactly what the WCF mexHttpBinding is complaining about.
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;
}