How to host Wcf service in IIS problem? - c#

i have read more articles but i can nto host wcf service in IIS
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="WcfSrv.MyProject.GetTables.ServiceCrm">
<endpoint address="" binding="wsHttpBinding" contract="WcfSrv.MyTechnic.GetTables.IService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/WcfSrv.MyProject.GetTables/ServiceTest/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True" />
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
MyCodes:These code wcf service codes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data.Objects;
namespace WcfSrv.MyProject.GetTables
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
public class ServiceTest : IService
{
public List GetAllData(string CustomerName)
{
using (CrmEntities crmCtx = new CrmEntities())
{
return crmCtx.GetAllDataCustomer(CustomerName).ToList();
}
}
}
}
i try to host my Wcf service 192.168.0.218 i added Srv file and dll new virtual directory but i can not use wcf service.How to make it? i changed config file Best Regards...

Have you (re)installed basic asp integration on IIS using aspnet_regiis -i
(C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis -i)
Since you don't specify the exact error it is hard to help, but the svc files need to be bound in IIS which rerunning the above statement usually resolves that problem.

WCF services hosted in IIS are represented as special content files (.svc files) inside the IIS application. See Hosting WCF Services in IIS section here how to use it and how to host you WCF service.

Related

Hosting WCF service from separate dll in WCF service application

I have a WCF service in a service library and I'm trying to host it in a WCF service application. I modified the .svc file accordingly
<%# ServiceHost Language="C#" Debug="true" Service="Mandrake.Service.OTAwareService" Factory="Mandrake.Service.OTServiceHostFactory" %>
And I added the stuff that was originally in the service library's app config to the service application's web.config file. I thought it overrides the settings defined in the library's app.config, but it turned out if I remove the app.config file from the library and host the service application on IIS with the web.config containing the necessary endpoint setup (which worked previously) the service doesn't get started and says I have no endpoint defined.
My web.config's servicemodel section is as follows:
<system.serviceModel>
<serviceHostingEnvironment>
<serviceActivations>
<add service="Mandrake.Service.OTAwareService"
factory="Mandrake.Service.OTServiceHostFactory"
relativeAddress="OTService.svc"/>
</serviceActivations>
</serviceHostingEnvironment>
<behaviors>
<serviceBehaviors>
<behavior name="StandardBehavior">
<serviceMetadata />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Mandrake.Service.OTAwareService" behaviorConfiguration="StandardBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8062/OTService"/>
</baseAddresses>
</host>
<endpoint address="" binding="netTcpBinding" name="TcpEndpoint" contract="Mandrake.Service.IOTAwareService" />
<endpoint address="mex" binding="mexTcpBinding" name="MetadataEndpoint" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Is there a way I can host this service from the service library in my service application?
Most probably you may not have net.tcp binding enabled on website where you are hosting your service application. Check in iis if net.tcp is there in list of bindings.

Succeed to connect my WCF service only from local machine unless machine ip address is specified instead of localhost

I have WCF service that clients connect to this service and do some operations.
This is my app.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="WCFServiceHostingInWinService.MySampleWCFService">
<endpoint
name="ServiceHttpEndPoint"
address=""
binding="basicHttpBinding"
contract="WCFServiceHostingInWinService.IMySampleWCFService">
</endpoint>
<endpoint
name="ServiceMexEndPoint"
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://192.168.0.192:8733/MySampleWCFService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
This service installed on several machines but on each machine i need to change the <add baseAddress="http://192.168.0.192:8733/MySampleWCFService/" /> to the relevant IP address in order it to work, when specified localhost instead of Machine IP address i can connect to my service only from local machine.
Use 0.0.0.0 on base address, It should work for every network interface on system regardless of the address of it. localhost doesn't work because it call the DNS lookup, which evaluates to 127.0.0.1, that's serve only local.

There was no endpoint listening although there is no firewall running

I try to build an application to send messages between 2 machines usinf WCF according this article: http://www.youtube.com/watch?v=1-BYIQQYwjQ
After follow all the steps and when the server and the client runs on the same machine all works fine.
when moved my Client (simple console application) to another machine i have changed localhost from http://localhost:8733/MySampleWCFService/ to my machine IP address (both machines in the same network and there is no Firewall running but received the error
There was no endpoint listening
This is my App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="WCFServiceHostingInWinService.MySampleWCFService">
<endpoint
name="ServiceHttpEndPoint"
address=""
binding="basicHttpBinding"
contract="WCFServiceHostingInWinService.IMySampleWCFService">
</endpoint>
<endpoint
name="ServiceMexEndPoint"
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/MySampleWCFService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Maybe it could be an permissions issue ?

C# WCF cant see app.config

Ok so here is my scenario.
I have made a WCF Library project. Configured my app.config file. I then created a new console application. Added my WCF Library project to the console app. Then I copied the config file over to my server console app. However, when I run the console application it throws an exception and essentially states that it cant see the app.config file. However, the app.config is clearly inside of the server console application. I can add my endpoints programmatically and make the service work. However, that is not my intention. Is there some sort of trick in order to get the ServiceHost to use the app.config, or more importantly the project to see the app.config?
My app.config
<configuration>
<configSections>
</configSections>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="serviceBehavior" name="Services">
<endpoint address="CompanyService" binding="netTcpBinding" bindingConfiguration=""
name="NetTcpBinding" contract="Services.ICompany" />
<endpoint binding="mexHttpBinding" name="mex" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8732/Services/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
My Host Service code:
using (ServiceHost host = new ServiceHost(typeof(Company))) {
host.Open();
Console.WriteLine("Press <ENTER> to terminate the host service");
Console.ReadLine();
}
It then throws this exception:
Unhandled Exception: System.InvalidOperationException: Service 'Services.Company' has zero application (non-infrastructure) endpoints. This might
be because no configuration file was found for your application, or because no
service element matching the service name could be found in the configuration fi
le, or because no endpoints were defined in the service element.
What are you naming the app.config file when you copy it over to the console app? There are specific rules that will need to be followed.
If the console app has an executable name of, e.g. "consoleapp.exe", then the app.config will have to have the name "consoleapp.exe.config"
Is the problem that you have called the file app.config, and not yourprogramname.exe.config?
#Jaochim The error says it's looking for a service named Services.Company while your config seems to have it attributed with name="Services" Try changing that.

IMetadataExchange issue in WCF

I am using VSTS 2010 + C# + .Net 4.0 + IIS 7.5 + Windows 7. I am following MSDN sample here without any modifications, http://msdn.microsoft.com/en-us/library/ms733766.aspx
When I open the service.svc file (in IIS manager, right click the svc file and select browse) in IIS, there is an error like this, any ideas what is wrong?
in the service list CalculatorService not find the protocol name "IMetadataExchange". Add ServiceMetadataBehavior to the configuration file or directly add to the ServiceHost
Here is the web.config I am using,
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<!-- This section is optional with the default configuration
model introduced in .NET Framework 4 -->
<service name="Microsoft.ServiceModel.Samples.CalculatorService">
<!-- This endpoint is exposed at the base address provided by host: http://localhost/servicemodelsamples/service.svc -->
<endpoint address=""
binding="wsHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
<!-- The mex endpoint is exposed at http://localhost/servicemodelsamples/service.svc/mex -->
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
</configuration>
Can you please give some details about they way you have configured ur service.
http://msdn.microsoft.com/en-us/library/ms734765.aspx
This link has the steps. Point 5 and 6 should be of ur interest.
pavan
Try adding this to behavior to Config file:
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
and change the service element to ADD this behavior :
<service
name="Microsoft.ServiceModel.Samples.CalculatorService"
behaviorConfiguration="CalculatorServiceBehavior">
regards,
PAvan

Categories

Resources