I have the following configuration file for WCF service. There is a host defined in the config. Still, when I print the service address from the client, it does not know about the host. The printed result is:
http://localhost:3187/Service1.svc/MyFolder
Why doesn’t it take into account the host name? What modification do we need to do for it?
Note: I am running from VS 2010 for running service and client website.
Service1Client myClientService = new Service1Client();
Response.Write(myClientService.Endpoint.Address);
Client Configuration (Autogenerated by Visual Studio)
<client>
<endpoint address="http://localhost:3187/Service1.svc/MyFolder"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
contract="MyWCFReference.IService1" name="WSHttpBinding_IService1">
<identity>
<userPrincipalName value="U16990#ustr.com" />
</identity>
</endpoint>
</client>
The server side configuration is:
<services>
<!--MyService-->
<service name="MyWCFServiceApplication.MyService"
behaviorConfiguration="WeatherServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:80/ServiceModelSamples/FreeServiceWorld"/>
</baseAddresses>
</host>
<endpoint address="MyFolder"
binding="wsHttpBinding"
contract="MyWCFServiceApplication.IService1" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WeatherServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
When a WCF service is hosted in an ASP.NET process, through either IIS or the ASP.NET Development Server (a.k.a Cassini), the baseAddresses setting in the service's configuration file is ignored since the service will always be reachable through the URL of the SVC file.
The URL you're seeing on the client is therefore correct:
http://localhost:3187/Service1.svc/MyFolder
As you can see, the base address of the service becomes the URL of the SVC file on the web server.
You're talking about a WCF client - yet, the config you posted only contains config for a service (the server side) ... (the <services> section).
I can't see any client configuration in what you posted - there ought to be a <client> section in your config somewhere
Related
I keep getting this error when I run the test client
Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.
Cannot obtain Metadata from http://localhost:50507/Service1.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:50507/Service1.svc Metadata contains a reference that cannot be resolved: 'http://localhost:50507/Service1.svc'. The requested service, 'http://localhost:50507/Service1.svc' could not be activated. See the server's diagnostic trace logs for more information.HTTP GET Error URI: http://localhost:50507/Service1.svc There was an error downloading 'http://localhost:50507/Service1.svc'. The request failed with the error message:-- The type 'AgeCalculator.Service1', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
I have already exposed the metadata of the service with the following code in the web.config file
<system.serviceModel>
<services>
<service name="AgeCalculator.CalculateAge" behaviorConfiguration="MetadataBehavior">
<endpoint address=""
binding="basicHttpBinding" contract="AgeCalculator.IService1">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="http://localhost/Service1.svc" binding="basicHttpBinding" contract="AgeCalculator.IService1"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MetadataBehavior">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
I have looked at all current documentation and don't know what the issue is. May be a naming convention as I am brand new to WCF but not seeing this. I have scoured the internet and exposing the metadata articles to apply fixes and nothing has worked to date
Since you don't seem to be using the default port, it is best to specify the port in your service binding. Change your service definition like this:
<services>
<service name="AgeCalculator.CalculateAge" behaviorConfiguration="MetadataBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:50507/" />
</baseAddresses>
</host>
<endpoint address=""
binding="basicHttpBinding" contract="AgeCalculator.IService1" />
<endpoint address="mex"
binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="http://localhost:50507/Service1.svc"
binding="basicHttpBinding" contract="AgeCalculator.IService1"/>
</service>
</services>
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.
I have a WCF Service running on my local machine
Everything themes to be running okay
Question is
if i can Invoke this WCF Service on my local machine browser
why it is not available on other machines
what i have tried :
my service address was localhost : port on the other machine i replaced the localhost with the ip of the machine where my WCF service is running and it didn't work
in my App.config i changed the baseaddress as you can see below from localhost to the machine ip and it didn't work either
i created a web application and call my service using getJson and it worked on my local machine browser and not on any of the other machine it loads the whole page and gives me error on getJson
what i am missing here ??? i don't know
IService1.cs
[OperationContract]
[WebGet(UriTemplate = "GetName/{name}",
ResponseFormat = WebMessageFormat.Json)]
List<Eval> GetName(string name);
App.config
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true"></binding>
</webHttpBinding>
</bindings>
<services>
<service name="WcfServiceLibrary1.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://192.168.1.5:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/" />
</baseAddresses>
</host>
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="WcfServiceLibrary1.IService1" behaviorConfiguration="web">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
WCF Test Client
Browser
It might be that firewall is stopping service call. Open inbound connection on port 8733 on machine where WCF is hosted. In case of Windows, open the Windows Firewall with Advanced Security dialog box, in the left pane, click Inbound Rules, and then, in the right pane, click New Rule and select Port option.
I made a service using the WCF discovery. Everything works fine when it is deployed on a specific port (using VS2010 debug), but when I try to deploy it to IIS it finds the service but can't run any of the methods.
This is the code:
DiscoveryClient discoverclient = new DiscoveryClient(new UdpDiscoveryEndpoint());
FindResponse response = discoverclient.Find(new FindCriteria(typeof(IService)));
EndpointAddress address = response.Endpoints[0].Address;
ServiceClient client = new ServiceClient(new BasicHttpBinding(), address);
Console.WriteLine(client.getMsg()); //some test function
Console.ReadKey();
When tring to run the client.getMsg() method I get the following error:
EndpointNotFoundException:
There was no endpoint listening at
http://computerName.domain/services/Service.svc that could accept the
message. This is often caused by an incorrect address or SOAP action.
See InnerException, if present, for more details.
But I got the address, meaning it found it. And if I use the debug deployer (not to iis) I find it in http://localhost:port/services/Service.svc and it runs perfectly fine. How can I have it deployed to iis with no problems?
OS : win7 64 bit
config file :
<services>
<service behaviorConfiguration="RemoteDeploy.Service1Behavior"
name="RemoteDeploy.Service">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
contract="RemoteDeploy.IService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint name="udpDiscoveryEpt" kind="udpDiscoveryEndpoint" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="RemoteDeploy.Service1Behavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceDiscovery>
</serviceDiscovery>
</behavior>
</serviceBehaviors>
</behaviors>
First try to GET http://computerName.domain/services/Service.svc in your browser - either you get an error or service description..
My WCF service is being hosted as a Windows managed service, so I'm unsure of whether or not I can still use the netTcpBinding. I've tried following a couple of guides at MSDN, but for some reason my service always fails to start whenever I do the switch from basicHttpBinding. Perhaps there are additional steps that services outside of the IIS are required to undergo?
Yes you can host WCF service with netTcpBinding outside of IIS, in Windows service or even Console Application if you want to.
Here is config file sample:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceBehavior"
name="XX.XX.Service">
<endpoint address=""
binding="netTcpBinding"
bindingConfiguration="BindingConfiguration"
contract="XX.XX..IService" />
<endpoint address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8731/XXService" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding
name="BindingConfiguration">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
[Edit]
Problems with your config file:
base address is http instead of net.tcp
metadata endpoint is mexHttpBinding instead of metTcpBinding
security - by default windows authorization will be used, if test communication between to boxes, you might have permission problem. I suggest to start with security mode None and then adjust security when everything else works.
you don't need to specify httpGetEnabled for service behavior
if the port that you are going to use is already in use, you will not be able to start service
You absolutely can, and I'd go so far as to say you should.
Here's your problem:
<services>
<service name="Server.FileService" ...
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/Test/file"/>
</baseAddresses>
</host>
<endpoint address="" binding="netTcpBinding" contract="Server.IFile" />
<endpoint address="mex" binding="mexHttpBinding" ...
The net.tcp address must have a net.tcp:// prefix, not a http:// prefix.
I don't normally use baseAddress so can't give advice on that. I'd remove baseAddress and instead use
<endpoint address="net.tcp://localhost:8001/Test/file" ..
(note that I would also choose another port over 8000)