HTTP request was forbidden by the client authentication scheme 'Anonymous - c#

I was digging a lot in stackoverflow.com to find answer for error: "HTTP request was forbidden by the client authentication scheme 'Anonymous", but none of proposed solutions solves my problem. So I decided to show my config files and ask about help.
I have WCF web service secured with SSL. All is fine until I started editin my WinForms Client which throws all the time error: "HTTP request was forbidden by the client authentication scheme 'Anonymous".
This is my WCF web service configuration file:
<?xml version="1.0" encoding="utf-8"?>
<bindings>
<wsHttpBinding>
<binding name="MBServiceBinding" closeTimeout="00:05:00" openTimeout="00:05:00"
receiveTimeout="00:05:00" sendTimeout="00:05:00" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8"
useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" />
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviors">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="SkillsAndTasks.CustomValidator, SkillsAndTasks"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="wsHttpBinding" scheme="https" bindingConfiguration="MBServiceBinding" />
</protocolMapping>
<services>
<service behaviorConfiguration="ServiceBehaviors" name="SkillsAndTasks.MBService">
<endpoint binding="wsHttpBinding" contract="SkillsAndTasks.IMBService" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0" />
And this is my WinForms App.config file:
<?xml version="1.0" encoding="utf-8" ?>
<applicationSettings>
<SkillsAndTasksDesktopClient.Properties.Settings>
<setting name="MBService" serializeAs="String">
<value>https://127.0.0.1/MBService.svc</value>
</setting>
<setting name="MBServiceLogin" serializeAs="String">
<value>ws1349</value>
</setting>
<setting name="MBServicePassword" serializeAs="String">
<value>qqlka123</value>
</setting>
</SkillsAndTasksDesktopClient.Properties.Settings>
</applicationSettings>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IMBService" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://127.0.0.1/MBService.svc" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IMBService" contract="MBService.IMBService"
name="WSHttpBinding_IMBService">
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</client>
</system.serviceModel>
Certainly I can preview web service in browser. I have binded my site with self-signed certificate (https) too.
I suspect that it must be something with security settings...

Related

IsContentTypeSupported method is implemented properly

I have implemented a WCF service for connecting c# project with SAP.
But I receive the following error when I try to start the service. The error is as follows
The content type text/html; charset=iso-8859-1 of the response message does not match the content type of the binding (multipart/related; type="application/xop+xml"). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 442 bytes of the response were:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode> soap:Server </faultcode>
<faultstring xml:lang="en"> RABAX occurred on server side </faultstring>
<detail>
<sap:Rabax xmlns:sap="http://www.sap.com/webas/710/soap/runtime/abap/fault/generic">
<SYDATUM>20170904</SYDATUM>
<SYUZEIT>152028</SYUZEIT>
<ERRORCODE>SYNTAX_ERROR</ERRORCODE>
</sap:Rabax>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
The following is my IIS config file for the WCF Service.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<system.web>
<compilation targetFramework="4.5" />
<pages controlRenderingCompatibilityVersion="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="CustomBehavior">
<clientCredentials>
<httpDigest impersonationLevel="None" />
</clientCredentials>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="CustomBinding_HTTP">
<binaryMessageEncoding maxReadPoolSize="64" maxWritePoolSize="64" maxSessionSize="2147483647">
<readerQuotas maxDepth="300" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binaryMessageEncoding>
<httpTransport manualAddressing="false" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" allowCookies="false" authenticationScheme="Anonymous" bypassProxyOnLocal="false" decompressionEnabled="true" hostNameComparisonMode="StrongWildcard" keepAliveEnabled="true" maxBufferSize="2147483647" proxyAuthenticationScheme="Anonymous" realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="true" />
</binding>
<binding name="bindingBAPI" receiveTimeout="00:10:00" sendTimeout="00:05:00">
<mtomMessageEncoding messageVersion="Soap11"></mtomMessageEncoding>
<httpTransport authenticationScheme="Basic" realm="SAP NetWeaver Application Server[SC3/900]"></httpTransport>
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="my end point address" binding="customBinding" bindingConfiguration="bindingBAPI" contract="ServiceReferenceBAPI.z_bedmanagement" name="BAPIEndpoint" />
</client>
<services>
<service name="Cerner.BM.Outbound.Service.BM_OutboundService">
<endpoint address="" binding="customBinding" bindingConfiguration="CustomBinding_HTTP" name="BM_OutboundService" contract="Cerner.BM.Outbound.Service.IBM_OutboundService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<!-- Client and institution value for successful BAPI Connection. -->
<appSettings>
<add key="BAPI_Client" value="" />
<add key="BAPI_Institution" value="" />
<add key="BAPI_UserName" value=""/>
<add key="BAPI_Password" value=""/>
</appSettings>
</configuration>

pass long string to wcf bebservice

For testing I have a little selfhosted webservice that returns the length of a submitted string.
It works fine with strings shorter or equal 32767 but loger strings are cut off.
I am testing with WCFtestclient and also adjusted the buffers in the client config.But it seems to be ignored. Found a lot of samples with IIS hosted services that just increase the buffers and it seems to work. in selfhosting it seems that it does not.
This is my app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="NewBinding0" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" transferMode="Buffered"
messageEncoding="Text">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://CELSIUS:8080/RWService/RWService.svc"
binding="basicHttpBinding" bindingConfiguration="NewBinding0"
contract="RWOrderServiceWCF.IRWWCFService" name="testclient"
kind="" endpointConfiguration="">
<identity>
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
</client>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior0">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="NewBehavior0" name="RWOrderServiceWCF.RWWCFService">
<endpoint address="RWService.svc" binding="basicHttpContextBinding"
bindingConfiguration="" contract="RWOrderServiceWCF.IRWWCFService"
isSystemEndpoint="false" />
<host>
<baseAddresses>
<add baseAddress="http://CELSIUS:8080/RWService" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>

The caller was not authenticated by the service

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

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>

Categories