WCF Service won't work under HTTPS / SSL - wcf

I have a WCF service that I'm using in my Silverlight project. I've followed pretty much any information on how to set up https and ssl for WCF services. The service can be called perfectly fine if SSL in not required but I noticed while examining the communications with fiddler that the WCF service was still in http protocol. Further more if I enable SSL the WCF service cant be browsed in a browser (right clicking in VS2010 -> selecting browse) .
My suspicion is that the service is still being called on some internal method with the http protocol.
Any suggestions to how to fix this?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="AuthService.customBinding" >
<binaryMessageEncoding />
<httpsTransport />
</binding>
</customBinding>
</bindings>
<services>
<service name="AuthService">
<endpoint address="" binding="customBinding" bindingConfiguration="AuthService.customBinding" contract="AuthService" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
</configuration>
Thanks

Any specific reason on why you are using a custom binding. Also your service name attribute and contract attribute needs to be fully qualified.
You can use simple basicHttpBinding if you want your WCF service to be compliant with basic profile 1.1 which allows non .NET clients to access as well.

Related

The HTTP request was forbidden with client authentication scheme 'Anonymous'. - Wcf test client

I've developed a wcf service with basichttpbinding. I've hosted the service on web server. There is a load balancer which exposes this service through https url. When i try to access the endpoint address exposed via load balancer it throws error in wcf test client - "The HTTP request was forbidden with client authentication scheme 'Anonymous'."
Below is the web.config configuration:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="testServiceBehavior">
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceSecurityAudit auditLogLocation="Application" suppressAuditFailure="false"
serviceAuthorizationAuditLevel="SuccessOrFailure" messageAuthenticationAuditLevel="SuccessOrFailure" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="testServiceBehavior" name="TestService">
<endpoint address="" binding="basicHttpBinding"
contract="TestService.IService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
Make sure to enable anonymous authentication in IIS:
If this value is set to Disable, the client needs to provide Windows identity information when calling.

Could not find default endpoint element while acessing WCF service

I am unable to consume the wcf restful service hosted in IIS.i.e at http://192.168.100.87:7001/ProductRESTService.svc/.
I have created a client application and added the service reference and created the proxy for service and accesing the using prxoy.
The error is:
Could not find default endpoint element that references contract 'ServiceReference2.IProductRESTService' 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 contract could be found in the client element.
My web.config file of service is following.
<system.serviceModel>
<services>
<service name="MyRESTService.ProductRESTService" behaviorConfiguration="serviceBehavior">
<endpoint address=""
binding="webHttpBinding"
contract="MyRESTService.IProductRESTService"
behaviorConfiguration="web"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
hi, please check my client configuration file.
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ICreate_Restful_WCF_Service"/>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://192.168.1.xxx:2777/ProductRESTService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICreate_Restful_WCF_Service" contract="ServiceReference1.IProductRESTService" name="BasicHttpBinding_ICreate_Restful_WCF_Service"/>
</client>
</system.serviceModel>
</configuration>
Why do you use client applicatin for rest service? For rest service, we could call it directly by httpWebRequest. Add Service Reference uses WSDL or ws-metadataExchange, and rest does not have metadata. If you use add service reference, it will not generate any app.config settings, and it will produce this error. If you want to try add service reference to use wcf service, you need to use soap service instead of rest service.

Silverlight WCF service binding error, "The remote server ..:Not found"

this is my first post on here. Normally, I find my answer on other threads, but this time I'm really stumped.
I have a Silverlight App and I can connect to my webservice to send/receive data just fine, except for one page that I have. All the other pages, I can get data, make changes and send it back to the service. This one page, I try to send data to a service and it gives me a login box for the web server. Whether I put in my credentials or not, I get the error "The remote server returned an error: Not found." I have a combobox that gets loaded on Page Load event and it gets the data from the service just fine.
Any help is appreciated.
Here is my web.config file:
<configuration>
<system.web>
<authentication mode="Windows"/>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="Network_Integrity_Control_Panel.Web.Service_AD_SQL.customBinding0">
<binaryMessageEncoding />
<httpTransport authenticationScheme="Negotiate"/>
</binding>
</customBinding>
</bindings>
<serviceHostingEnvironment
aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="Network_Integrity_Control_Panel.Web.Service_AD_SQL">
<endpoint address="" binding="customBinding" bindingConfiguration="Network_Integrity_Control_Panel.Web.Service_AD_SQL.customBinding0"
contract="Network_Integrity_Control_Panel.Web.Service_AD_SQL" />
<endpoint address="mex" binding="customBinding" bindingConfiguration="Network_Integrity_Control_Panel.Web.Service_AD_SQL.customBinding0"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
</configuration>
Firstly , Welcome to SO .
It gives you a login box because your Authentication mode is Windows
What I see from your config your endpoint address is empty address="".
You should give the address in your code or in your config file.
Have a look at Microsoft resources http://msdn.microsoft.com/en-us/library/ff648505.aspx

Cannot set wsHttpBinding on Azure Web Role. Web.config ignored?

I'm trying to deploy a WCF service as a Windows Azure Role using wsHttpBinding.
When the client tries to connect to it, it keeps getting the following exception:
[SynchronizingContextState.Process] [System.Net.WebException: The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..]
at System.Net.HttpWebRequest.GetResponse()
at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
This would seem to indicate that the service is using basicHttpBinding instead. However, I checked my Web.config many times and can't seem to find anything wrong. Plus, the same service works perfectly when being hosted outside Azure.
I connected to the Azure VM and confirmed that the correct Web.config is deployed, but it looks as if it's just being ignored, because I cannot get the service metadata either, even though it's supposedly enabled.
Here's my Web.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="BackendServiceBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="BackendServiceBinding" maxReceivedMessageSize="655360">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="MyNamespace.BackendService" behaviorConfiguration="BackendServiceBehavior">
<endpoint name="Backend" address="" binding="wsHttpBinding" bindingConfiguration="BackendServiceBinding" contract="MyNamespace.IBackendService" />
<endpoint name="BackendMex" address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/BackendService.svc" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
Am I missing something here? Thank you very much.
Did you try adding to the endpoint behavior?
<behavior name="web">
<webHttp />
</behavior>
(if you want MEX to be working do it for it to too)
Ok, I finally fixed it, it was a bad case of PEBKAC. =/
I've seen somebody have the same problem because he didn't include the namespace in the service name so I suspected it was a namespace issue, but I've looking at the wrong place all the time.
Turns out the Azure implementation for the service was defined in the wrong namespace. I corrected it and voilá, now it works.
Hope this is useful to somebody else, at least.

When adding WCF service reference, configuration details are not added to web.config

I am trying to add a WCF service reference to my web application using VS2010. It seems to add OK, but the web.config is not updated, meaning I get a runtime exception:
Could not find default endpoint
element that references contract
'CoolService.CoolService' 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 contract could
be found in the client element.
Obviously, because the service is not defined in my web.config. Steps to reproduce:
Right click solution > Add > New Project > ASP.NET Empty Web Application.
Right click Service References in the new web app > Add Service Reference.
Enter address of my service and click Go. My service is visible in the left-hand Services section, and I can see all its operations.
Type a namespace for my service.
Click OK. The service reference is generated correctly, and I can open the Reference.cs file, and it all looks OK.
Open the web.config file. It is still empty!
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings />
<client />
</system.serviceModel>
Why is this happening? It also happens with a console application, or any other project type I try. Any help?
Here is the app.config from my WCF service:
<?xml version="1.0"?>
<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="CoolSQL.Server.WCF.CoolService">
<endpoint address=""
binding="webHttpBinding"
contract="CoolSQL.Server.WCF.CoolService"
behaviorConfiguration="SilverlightFaultBehavior">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/CoolSQL.Server.WCF/CoolService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
<behavior name="SilverlightFaultBehavior">
<silverlightFaults />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="DefaultBinding"
bypassProxyOnLocal="true"
useDefaultWebProxy="false"
hostNameComparisonMode="WeakWildcard"
sendTimeout="00:05:00"
openTimeout="00:05:00"
receiveTimeout="00:00:10"
maxReceivedMessageSize="2147483647"
transferMode="Streamed">
<readerQuotas maxArrayLength="2147483647"
maxStringContentLength="2147483647" />
</binding>
</webHttpBinding>
</bindings>
<extensions>
<behaviorExtensions>
<add name="silverlightFaults"
type="CoolSQL.Server.WCF.SilverlightFaultBehavior, CoolSQL.Server.WCF" />
</behaviorExtensions>
</extensions>
<diagnostics>
<messageLogging logEntireMessage="true"
logMalformedMessages="false"
logMessagesAtServiceLevel="true"
logMessagesAtTransportLevel="false"
maxMessagesToLog="3000"
maxSizeOfMessageToLog="2000" />
</diagnostics>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0"
sku=".NETFramework,Version=v4.0" />
</startup>
<system.diagnostics>
<sources>
<source name="System.ServiceModel.MessageLogging"
switchValue="Information, ActivityTracing">
<listeners>
<add name="messages"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="c:\messages.e2e" />
</listeners>
</source>
</sources>
</system.diagnostics>
</configuration>
I discovered how to work around this. My WCF service was implemented in its own project, and hosted in by a separate console application in the same solution. If I run the WCF service as the solution's startup project (eg. let VS host it for me) then adding the reference works fine and the correct lines are added to the client web.config. But if I host service from within my console application, while I can still add the reference, the client's web.config does not get modified. So, a workaround is to first let VS host the service, then add the reference, then change the service to be hosted (at the same address and port) in the console application.
This is surprising behaviour, and I am curious if anyone can shed any light on it?