Hey fellow developers and software-engineers,
I've recently run into a problem which doesn't let me access my WCF Services with a 404 (using ChannelFactory).
Here are the details:
multiple Webservers hosting the same WS (WCF.Net4/IIS8.5)
Server web.config of each WS:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true"/>
</webHttpBinding>
<basicHttpBinding>
<binding name="" maxReceivedMessageSize="26144"/>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="enableScriptBehaviour">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="IISManagerWS.WS">
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="enableScriptBehaviour" contract="ContractDll.IWS"/>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="True" />
</system.serviceModel>
</configuration>
Important Note for the WS: I've used a ClassLibrary for the Service Contract so I could work with the ChannelFactory in the client.
Why I am using a ChannelFactory? It simply seemed the easiest way to consume multiple WS which are all the same. Because the number
of these Webservices can become more I'd wanted it to be dynamically via code.
Interface of the Contract Dll:
namespace ContractDll
{
[ServiceContract]
public interface IWS
{
[WebGet()]
[OperationContract]
WebSite[] getLocalSiteInventory();
}
[DataContract]
public class WebSite
{
[DataMember]
public String Name { get; set; }
[DataMember]
public String AppPool { get; set; }
[DataMember]
public String Authentication { get; set; }
[DataMember]
public String Path { get; set; }
[DataMember]
public String Server { get; set; }
[DataMember]
public Boolean HasSSL { get; set; }
}
}
On the Client Side I've got an empty app.config except for the connectionstring, so nothing special here. The whole lot of magic should happen in the code behind:
BasicHttpBinding binding = new BasicHttpBinding();
EndpointAddress address = new EndpointAddress(ServiceURL);
ChannelFactory<IWS> factory = new ChannelFactory<IWS>(binding, address);
IWS channel = factory.CreateChannel(address);
WebSite[] sites = channel.getLocalSiteInventory();
But just when the call of my WS-Method gets going I happen to get an exception: There was no endpoint listening at 'http://dev-02.apps.rd.local/IISManagerWS/ws.svc' that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
And the inner Exception goes: (404) Not found.
If I access the WS via URL:
I've tried alot of research but even if there are lot of topics that look the same I had no success in solving this error.
Found the Solution myself while reading about designing RESTful Webservices.
WebChannelFactory<IWS> cf = new WebChannelFactory<IWS>(new Uri(ServiceURL));
IWS channel = cf.CreateChannel();
WebSite[] sites = channel.getLocalSiteInventory();