The caller was not authenticated by the service - c#

I am using WCF and found this error:
" The caller was not authenticated by the service."
I have used this code in client.config file:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSDualHttpBinding_IReceiverController" closeTimeout="00:00:05"
openTimeout="00:00:05" receiveTimeout="00:10:00" sendTimeout="00:00:05"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="None">
<message clientCredentialType="Windows" negotiateServiceCredential="false" />
</security>
</binding>
<binding name="WSHttpBinding_IEMRProWCFService" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://pionbuggs-pc:4567/EMRProWCFService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IEMRProWCFService"
contract="EMRProWCFService.IEMRProWCFService" name="WSHttpBinding_IEMRProWCFService">
<identity>
<dns value="http://pionbuggs-pc:4567/EMRProWCFService.svc" />
</identity>
</endpoint>
</client>
</system.serviceModel>
And below is the code in the service.config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<compilation />
<httpRuntime maxRequestLength="2147483647" />
</system.web>
<system.serviceModel>
<services>
<service name="WCFService.EMRProWCFService">
<endpoint address="" binding="wsHttpBinding" contract="WCFService.IEMRProWCFService">
<identity>
<dns value="http://pionbuggs-pc:4567/EMRProWCFService.svc" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" 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 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>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<webHttpBinding>
<binding name="WebConfiguration" maxBufferSize="65536" maxReceivedMessageSize="2147483647" transferMode="Streamed">
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
</system.webServer>
</configuration>

Instead of using binding="wsHttpBinding", try using just a basic, changing you client endopint to:
<endpoint address="http://pionbuggs-pc:4567/EMRProWCFService.svc"
binding="basicHttpBinding" bindingConfiguration="WSHttpBinding_IEMRProWCFService"
contract="EMRProWCFService.IEMRProWCFService" name="WSHttpBinding_IEMRProWCFService">
and on your service to:
<endpoint address="" binding="basicHttpBinding" contract="WCFService.IEMRProWCFService">
The error is that you use advanced security that requires you to use authentication, unless there are security constrains that require it.
Here's some info about it:
BasicHttpBinding vs WsHttpBinding vs WebHttpBinding

Related

WCF WsDualHttpBinding The caller was not authenticated by the service

I am attempting to implement a simple chat service using WCF (WsDualHttpBinding) so i can make use of the Callbacks.
My WCF service is hosted under IIS (8.5 I believe) under Arvixe shared hosting.
When I test my client and my service on my PC everything works like a charm. When I publish my service on Arvixe host and attempt to open a connection from the client app running on my pc (using visual studio) I get: "The caller was not authenticated by the service".
The service is hosted here:
http://www.4greatsoft.com/WebService/ChatSVC.svc
I can also get the service description with:
http://www.4greatsoft.com/WebService/ChatSVC.svc?wsdl
The firewall on the client PC is off.
My service model configuration on the CLIENT (app.config) side is:
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IChat" />
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://www.4greatsoft.com/WebService/ChatSVC.svc"
binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IChat"
contract="IIS_ChatSVC.IChat" name="WSDualHttpBinding_IChat">
<identity>
<userPrincipalName value="PINE\4greatsoftcom_web" />
</identity>
</endpoint>
</client>
</system.serviceModel>
My service model configuration on the SERVER (web.config) side is:
<system.serviceModel>
<protocolMapping>
<add scheme="http" binding="wsDualHttpBinding" bindingConfiguration="wsDualHttpBindingConfiguration" />
</protocolMapping>
<bindings>
<wsDualHttpBinding>
<binding name="wsDualHttpBindingConfiguration" transactionFlow="true" >
</binding>
</wsDualHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="ServiceAssembly.ChatService">
<endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="wsDualHttpBindingConfiguration" contract="ServiceAssembly.IChat" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Those service model configuration will yield a "The caller was not authenticated by the service" error.
Following many suggestions on stackoverflow, I attempted to turn off security using the service model configuration bellow, but when doing so I get the following timeout error: "The open operation did not complete within the allotted timeout of 00:00:09.7659996."
My service model configuration (causing timeout) on the CLIENT (app.config) side is:
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IChat" closeTimeout="00:00:10"
openTimeout="00:00:10" receiveTimeout="00:10:00" sendTimeout="00:00:10"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="None">
<message clientCredentialType="None" negotiateServiceCredential="false" />
</security>
</binding>
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://www.4greatsoft.com/WebService/ChatSVC.svc"
binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IChat"
contract="IIS_ChatSVC.IChat" name="WSDualHttpBinding_IChat">
</endpoint>
</client>
</system.serviceModel>
My service model configuration (causing timeout) on the SERVER (web.config) side is:
<system.serviceModel>
<protocolMapping>
<add scheme="http" binding="wsDualHttpBinding" bindingConfiguration="wsDualHttpBindingConfiguration" />
</protocolMapping>
<bindings>
<wsDualHttpBinding>
<binding name="wsDualHttpBindingConfiguration" closeTimeout="00:00:10"
openTimeout="00:00:10" receiveTimeout="00:10:00" sendTimeout="00:00:10"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="None" />
</binding>
</wsDualHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="ServiceAssembly.ChatService">
<endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="wsDualHttpBindingConfiguration" contract="ServiceAssembly.IChat" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
IMPORTANT:
please note that the use of "WsDualHttpBinding" is mandatory in my use case as I am using the CallBack feature of WCF. So NO I can't use "HttpBasicBinding".
To be brutally honest, I must admit that I am a total noob as far as networking security is concerned and I am clueless as to how to fix this. I have been on a "trial and error" binge for over 3 days trying all kinds of permutation to my service model configuration with no success...
That said, I would ask any would-be helper to be precise in there suggestion and not assume that I am a expert in the subject matter...
I believe this post (WCF Client not able to negotiate security access with Service running in a different machine) comes close to explaining my problem but I still can't see what my solution must be.
At this point I am almost willing to contract a WCF/IIS expert to see this through if only I knew where to find one...
Thank you all for your attention.

WCF - "The request for security token could not be satisfied because authentication failed"

I've created a WCF service and hosted it in IIS7/Windows Server 2008.
I'm trying to consume the service in my application...
When I run the application from Visual Studio (debug), I can call the service and everything works as expected, however, when I attempt to call the service from the published application, I get the error above.
Here's the service's web.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
...
</connectionStrings>
<system.web>
<compilation debug="false" />
</system.web>
<runtime>
<generatePublisherEvidence enabled="false"/>
</runtime>
<system.serviceModel>
<services>
<service name="SVCLIB.SERVICE1">
<endpoint address="" binding="wsHttpBinding" contract="SVCLIB.SERVICE1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/SVCLIB/SERVICE1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
And on the client:
SERVICE1.SERVICE1Client objService = new SERVICE1Client();
objService.ClientCredentials.Windows.ClientCredential.UserName = "UserName";
objService.ClientCredentials.Windows.ClientCredential.Password = "Password";
objService.GetData();
objService.Close();
It works when debugging the application in VS, but it doesn't work when running the published application.
Error:
The request for security token could not be satisfied because
authentication failed
I've looked at many posts here on Stack Overflow and others, but none helped me so far.
Thank you!
** EDIT:
This is on the web.config, in the client side:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_SERVICE1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://server.samedomain.com:8000/SVCLIB.SERVICE1.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_SERVICE1"
contract="SERVICE1.ISERVICE1" name="WSHttpBinding_ISERVICE1">
</endpoint>
</client>
</system.serviceModel>
Tried gmail user's suggestion and link below... but still have the same problem. Same error.
I still don't know what the problem is.
But for now I switched to basicHttpBinding with Windows Authentication.
I'm not sure, but try commenting the following lines in the published environment
<identity>
<dns value="localhost" />
</identity>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/SVCLIB/SERVICE1/" />
</baseAddresses>
</host>

Soap web services error when hosting under virtual dir beneath REST services

I tried to find some solution on my own, but I failed. I have WCF web service hosted under virtual directory in IIS
http://host/soap/myservice.svc
Soap services are placed under REST services
http://host - REST services address
When I am trying to execute methods from the WCF service I get this error (on server side):
Failed to lookup a channel to receive an incoming message. Either the endpoint or the SOAP action was not found.
When I host the WCF service on the same IIS, but as an standalone application
http://host:81
everything works fine. But I need them to be under those REST services.
Here is client web.config generated by svcutil:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IMyService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://host/soapservices/MyService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyService"
contract="IMyService" name="WSHttpBinding_IMyService">
<identity>
<servicePrincipalName value="host/host" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
Here is web.config of soap service:
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="MyServiceName">
<host>
<baseAddresses>
<add baseAddress="http://host/SOAPServices/MyService/" />
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="IMyService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>

WCF Client Security defaulting to Windows

I am trying to setup a simple WCF web service with wsHTTPBinding and using a custom Username.
I have the service on a remote server setup with a self signed cert on a different port.
eg: https://service.myserice.com:442/service1.svc
For some reason the client seems to default to windows security even though I hjave set it up as UserName Security.
Here is my web Service config file:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"></customErrors>
</system.web>
<system.serviceModel>
<services>
<service name="AutoSenderWCF.Service1" behaviorConfiguration="Behavior1">
<host>
<baseAddresses>
<add baseAddress="https://service.autosender.com.au:442/" />
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" bindingName="TransportBinding" contract="AutoSenderWCF.IService1"></endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="TransportBinding">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="Behavior1">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" 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="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="AutoSenderWCF.CustomValidator, AutoSenderWCF"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
and my client code (notic ethe security=windows)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="TransportBinding_IService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://service.autosender.com.au/Service1.svc"
binding="wsHttpBinding" bindingConfiguration="TransportBinding_IService1"
contract="ServiceReference1.IService1" name="TransportBinding_IService1">
<identity>
<servicePrincipalName value="host/wserver" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
It is clearly specified to use Windows in your Client config:
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
Copy that section from Server config.
I beleive i have solved it:
this line.
<endpoint address="" binding="wsHttpBinding" bindingName="TransportBinding" contract="AutoSenderWCF.IService1"></endpoint>
it should not be bindingName it should be bindingConfiguration

SSL endpoint on a WCF service with only XML configuration file

I have a WCF Service with only the xml configuration file and the .exe (so not the complete solution). Can i make existing endpoints secure with https?
If so, how can i do this and how can i connect to it with my client which will be on another pc in the network?
this will be my service xml config:
my binding:
<wsHttpBinding>
<binding
name="HighQuotaWSHttpBinding"
receiveTimeout="00:10:00"
sendTimeout="00:10:00"
bypassProxyOnLocal="true"
maxBufferPoolSize="2147483647"
useDefaultWebProxy="false"
maxReceivedMessageSize="2147483647">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
my endpoint:
<service
behaviorConfiguration="WebDataServiceBehaviour"
name="Humiq.Integral.WebDataService.Impl.ServiceLayer.WcfLibrary.WebDataService">
<endpoint
address="WebDataService"
binding="wsHttpBinding" bindingConfiguration="HighQuotaWSHttpBinding"
contract="Humiq.Integral.WebDataService.Intf.ServiceLayer.IWebDataService"
name="WebDataServiceHttpBinding">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint
address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange"
name="mexManagement" />
<host>
<baseAddresses>
<add baseAddress="http://mylocalip:9650/" />
<add baseAddress="https://mylocalip:9651/" />
</baseAddresses>
</host>
</service>
behaviour:
<behaviors>
<serviceBehaviors>
<!-- Behavior for WebserviceData interface -->
<behavior name="WebDataServiceBehaviour">
<!-- Set throttling of (concurrent) cals -->
<serviceThrottling
maxConcurrentCalls="100"
maxConcurrentSessions="100"
maxConcurrentInstances="100"/>
<!-- 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="True" />
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
</serviceBehaviors>
</behaviors>
And this is my client:
<bindings>
<wsHttpBinding>
<binding name="WebDataServiceHttpBinding" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Transport">
<transport clientCredentialType="Basic" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://mylocalip:9651/WebDataService" binding="wsHttpBinding"
bindingConfiguration="WebDataServiceHttpBinding" contract="wcf1.IWebDataService"
name="WebDataServiceHttpBinding">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
you need to define the port to use ssl on windows.
it is done with the netsh command, you can read its help:
netsh http add sslcert ipport=0.0.0.0:8732 certhash=4745537760840034c3dea27f940a269b7d470114 appid={00112233-4455-6677-8899-AABBCCDDEEFF}

Categories