I’m encountering a problem in setting up a WCF service over SSL. The service is very simple which only returns “Hello World!”. The message could be received by the client over HTTP but not over HTTPS. I guess it’s the problem of my web.config setting but i can’t figure it out.
Besides, I could visit the HelloWorld.svc page on the server by browser but fail with my console program and WCF Test Client as well.
Here’s the error message:
System.ServiceModel.EndpointNotFoundException: There was no endpoint listening a
t https://fyp-pc13:997/HelloWorldService/HelloWorld.svc that could accept the me
ssage. This is often caused by an incorrect address or SOAP action. See InnerExc
eption, if present, for more details. ---> System.Net.WebException: The remote s
erver returned an error: (404) Not Found.
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpCha
nnelRequest.WaitForReply(TimeSpan timeout)
--- End of inner exception stack trace ---
The content of my Web.config on the WCF server:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IHelloService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport realm ="" clientCredentialType="None" />
</security>
<!--<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>-->
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="WSHttpBinding_IHelloService">
<security mode="Transport">
<transport realm ="" clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="HelloWorldService">
<!--<endpoint address="https://localhost:997/HelloWorldService/HelloWorld.svc" binding="wsHttpBinding" contract="WcfService.HelloWorld" />-->
<endpoint address="https://fyp-pc13:997/HelloWorldService/HelloWorld.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IHelloService" contract="WcfService1.IHelloService" name="WSHttpBinding_IHelloService" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</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 httpsGetEnabled="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>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
The content of my ServiceReferences.ClientConfig:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IHelloService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport realm ="" clientCredentialType="None" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="WSHttpBinding_IHelloService">
<security mode="Transport">
<transport realm ="" clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://fyp-pc13:997/HelloWorldService/HelloWorld.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IHelloService"
contract="ServiceReference1.IHelloService" name="WSHttpBinding_IHelloService">
<identity>
<dns value="fyp-pc13" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding"
contract="IMetadataExchange" />
</client>
</system.serviceModel>
</configuration>
HelloWorld.svc
<%@ ServiceHost Language="C#" Debug="true" Service="WcfService1.HelloWorld" CodeBehind="HelloWorld.svc.cs" %>
IHelloService.cs (Interface)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
namespace WcfService1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IHelloService
{
[OperationContract]
string GetData(int value);
[OperationContract]
CompositeType GetDataUsingDataContract(CompositeType composite);
[OperationContract]
string Hello();
// TODO: Add your service operations here
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class CompositeType
{
bool boolValue = true;
string stringValue = "Hello ";
[DataMember]
public bool BoolValue
{
get { return boolValue; }
set { boolValue = value; }
}
[DataMember]
public string StringValue
{
get { return stringValue; }
set { stringValue = value; }
}
}
}
Driver (main)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ConsoleApplication1.ServiceReference1;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
System.Net.ServicePointManager.ServerCertificateValidationCallback += (se, cert, chain, sslerror) =>
{
return true;
};
HelloServiceClient helloServiceClient = new HelloServiceClient();
string result = helloServiceClient.Hello();
if (result!=null)
{
Console.Out.WriteLine(result);
}
else
{
Console.Out.WriteLine("Fail");
}
}
catch (Exception e)
{
Console.Out.WriteLine(e.ToString());
}
}
}
}
Your client-side binding looks correct, but your server-side binding is not. Copy and paste your
WSHttpBinding_IHelloServicedefinition from client to server then reference it in your server endpoint.UPDATE:
Your
<service name="HelloWorldService">config definition needs to match the fully-qualified service class name, otherwise the activator won’t be able to match it up to the class name defined in the.svcfile, i.e.