Is this WCF configuration causing my 400 bad request? - c#

I have a WCF application hosted as a webrole in Azure with the following configuration. I am getting a 400 Bad Request when trying to access any of the three service wsdl in a browser or when trying to set up a proxy.
<?xml version="1.0"?>
<configuration>
<appSettings>
</appSettings>
<system.web>
<customErrors mode="Off"></customErrors>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<connectionStrings></connectionStrings>
<system.diagnostics>
<sharedListeners>
<add name="AzureLocalStorage" type="Example.AzureLocalStorageTraceListener, Example"/>
</sharedListeners>
<sources>
<source name="System.ServiceModel" switchValue="Verbose, ActivityTracing">
<listeners>
<add name="AzureLocalStorage" />
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Verbose">
<listeners>
<add name="AzureLocalStorage" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.serviceModel>
<services>
<service name="Service1" behaviorConfiguration="MetaBehavior">
<endpoint address="http://example.com/service1.svc" binding="basicHttpBinding" name="basicEndpoint1" contract="IService1" />
</service>
<service name="Service2" behaviorConfiguration="MetaBehavior">
<endpoint address="http://example.com/service2.svc" binding="basicHttpBinding" name="basicEndpoint2" contract="IService2" />
</service>
<service name="Service3" behaviorConfiguration="MetaBehavior">
<endpoint address="http://pexample.com/service3.svc" binding="basicHttpBinding" name="basicEndpoint3" contract="IService3" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MetaBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true"/>
<serviceThrottling maxConcurrentSessions="90" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" aspNetCompatibilityEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
I am pretty sure my configuration is not right but I need a little guidance with what is incorrect.
An interface is defined as:
[ServiceContract(Name = "Service1", Namespace = "http://example.com")]
public interface IService1
{
[WebGet]
[OperationContract]
Result Create();
}

You're using the wrong binding, try webHttpBinding instead of basicHttpBinding. Your contract is set to WebGet which is WCF's take on a quasi-REST based service. BasicHttpBinding is only for soap based bindings (hence the "Bad request" exception).
EDIT:
Since the WebGet was present, I assumed you didn't want soap endpoints. Below is a config that supports both soap and WebGet. I don't know how different Azure is from standard IIS but you should probably use relative addresses for your service. IIS will only support relative addresses in the service config.
<system.serviceModel>
<services>
<service name="Service1" behaviorConfiguration="Service.Behavior">
<endpoint address="Service1"
binding="basicHttpBinding"
contract="IService1"
bindingNamespace = "http://example.com"
bindingConfiguration="HttpBasic" />
<endpoint address="mexService1"
binding="mexHttpBinding"
contract="IMetadataExchange"
bindingNamespace = "http://example.com"/>
<endpoint address="webService1"
binding="webHttpBinding"
behaviorConfiguration="webBehavior"
contract="IService1"
bindingNamespace = "http://example.com"
name="webHttp"
listenUriMode="Explicit" />
</service>
<service name="Service2" behaviorConfiguration="Service.Behavior">
<endpoint address="Service2"
binding="wsHttpBinding"
contract="IService2"
bindingNamespace = "http://example.com"
bindingConfiguration="HttpStandard" />
<endpoint address="mexService2"
binding="mexHttpBinding"
contract="IMetadataExchange"
bindingNamespace = "http://example.com"/>
<endpoint address="webService2"
binding="webHttpBinding"
behaviorConfiguration="webBehavior"
contract="IService2"
bindingNamespace = "http://example.com"
name="webHttp"
listenUriMode="Explicit" />
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior" >
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Service.Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="HttpBasic" receiveTimeout="00:10:00" maxReceivedMessageSize="2048000">
<security mode="None"/>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="HttpStandard" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="2048000">
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="None" negotiateServiceCredential="false" algorithmSuite="Default" establishSecurityContext="false" />
</security>
</binding>
<binding name="Https" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="2048000">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="None" negotiateServiceCredential="false" algorithmSuite="Default" establishSecurityContext="false" />
</security>
</binding>
<binding name="HttpsAuthenticated" receiveTimeout="00:10:00" sendTimeout="00:10:00" maxReceivedMessageSize="2048000">
<security mode="Transport">
<transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>

Related

404 - Error: Getting Empty response from WCF Service is giving Error in Azure

From Azure it is giving, when I try to post to: https://wcf/service.svc/json/DoAction it comes back with an empty response.
Below is the webconfig
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="SampleService" behaviorConfiguration="ChallengeBehavior">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="ChallengeMessageEncoding" contract="IService123" behaviorConfiguration="SoapServiceBehavior" />
<endpoint address="/json" binding="webHttpBinding" bindingConfigu**strong text**ration="RestServiceMessageEncoding" contract="ISampleService" behaviorConfiguration="RestServiceBehavior" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="RestServiceBehavior">
<webHttp defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" />
</behavior>
<behavior name="SoapServiceBehavior">
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="RestServiceMessageEncoding">
<security mode="None">
</security>
</binding>
</webHttpBinding>
<wsHttpBinding>
<binding name="ChallengeMessageEncoding">
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" />
<message clientCredentialType="None" establishSecurityContext="false" negotiateServiceCredential="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
Enable the features of WCF in Add or remove programs in your local or in VM of Azure.

WCF: Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:8733/'

After adding serviceAuthorization to config file, a problem occurred. When adding a service to the project, it does not see the netTcp connection. Without serviceAuthorization everything works fine.
Config:
<system.serviceModel>
<services>
<service behaviorConfiguration="mexBehavior" name="ChartServices.Service.ChartManagerService">
<endpoint address="ChartServices" binding="wsHttpBinding" bindingConfiguration="wsBindingConfig"
name="wsBinding_UserService" contract="ChartServices.Services_Contract.IUserService" />
<endpoint address="ChartServices" binding="netTcpBinding" bindingConfiguration="netTcpBindingConfig"
name="netTcp_UserService" contract="ChartServices.Services_Contract.IUserService" />
<endpoint address="mex" binding="mexTcpBinding" name="mexTcp"
contract="IMetadataExchange" />
<endpoint address="mex" binding="mexHttpBinding" name="mexHttp"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8733/" />
<add baseAddress="http://localhost:8734/" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="wsBindingConfig">
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
</wsHttpBinding>
<netTcpBinding>
<binding name="netTcpBindingConfig">
<security mode="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="PeerTrust" />
</clientCertificate>
<serviceCertificate findValue="RootCATest" storeLocation="LocalMachine"
storeName="My" x509FindType="FindByIssuerName" />
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="ChartServices.CustomUserNameValidator, ChartServices" />
</serviceCredentials>
<serviceAuthorization principalPermissionMode="Custom" serviceAuthorizationManagerType="ChartServices.MyServiceAuthorizationManager, ChartServices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<authorizationPolicies>
<add policyType="ChartServices.AuthorizationPolicy, ChartServices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</authorizationPolicies>
</serviceAuthorization>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Tried different options but could not solve the problem
Visual Studio 2017 problem!!!!!!!
https://github.com/dotnet/wcf/issues/1741

Contains an unrecognized http body format value 'Xml'

There are a number of similar questions on stack overflow, but none have helped me formulate a solution.
Question below is the closest, but I couldn't get it to work and my other services stopped working when I tried to implement it.
WCF input huge XML as Stream with Content-Type: xml/text
Error: Incoming message for operation 'IncomingXML' (contract ... with namespace ...) contains an unrecognized http body format value 'Xml'. The expected body format value is 'Raw'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details.
Basically I need this and only this web service to accept "application/xml". At the moment it accepts only "raw", the service fails when the call has "application/xml" set.
The problem is two parts, one allow the service to accept xml and two, don't effect the other web services. This is the only service that accepts incoming xml.
Does anyone have any suggestions? If I can't get this to work without disrupting the other web services.
Contract
[OperationContract]
[WebInvoke(Method = "POST")]
void IncomingXML(Stream xml);
Service
public void IncomingXML(Stream xml)
{
}
Web.config:
<system.serviceModel>
<extensions>
...
</extensions>
<diagnostics>
...
</diagnostics>
<behaviors>
<endpointBehaviors>
<behavior name="jsonEndpointBehavior">
<webHttp helpEnabled="true" automaticFormatSelectionEnabled="true" defaultOutgoingResponseFormat="Json" defaultBodyStyle="WrappedRequest" faultExceptionEnabled="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<endpointDiscovery enabled="true" />
</behavior>
<behavior name="xmlEndpointBehavior">
<webHttp helpEnabled="false" defaultBodyStyle="WrappedRequest" defaultOutgoingResponseFormat="Xml" automaticFormatSelectionEnabled="true" faultExceptionEnabled="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
<behavior name="rawEndpointBehavior">
<webHttp helpEnabled="false" defaultBodyStyle="WrappedRequest" defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" faultExceptionEnabled="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="jsonBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" crossDomainScriptAccessEnabled="true" />
<binding name="jsonsBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" crossDomainScriptAccessEnabled="true">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
<binding name="xmlBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" crossDomainScriptAccessEnabled="true" />
<binding name="xmlsBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" crossDomainScriptAccessEnabled="true">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
<binding name="rawBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" crossDomainScriptAccessEnabled="true" />
<binding name="rawsBinding" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" crossDomainScriptAccessEnabled="true">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</webHttpBinding>
<basicHttpBinding>
<binding name="soapBinding" />
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="serviceBehavior" name="Namespace.Web.WCF.Service">
<endpoint address="json" behaviorConfiguration="jsonEndpointBehavior" binding="webHttpBinding" bindingConfiguration="jsonBinding" name="jsonHttpEndpoint" bindingName="Namespace.Service.JsonHttp" contract="Namespace.Web.WCF.IService" />
<endpoint address="json" behaviorConfiguration="jsonEndpointBehavior" binding="webHttpBinding" bindingConfiguration="jsonsBinding" name="jsonHttpsEndpoint" bindingName="Namespace.Service.JsonHttps" contract="Namespace.Web.WCF.IService" />
<endpoint address="xml" behaviorConfiguration="xmlEndpointBehavior" binding="webHttpBinding" bindingConfiguration="xmlBinding" name="xmlHttpEndpoint" bindingName="Namespace.Service.XmlHttp" contract="Namespace.Web.WCF.IService" />
<endpoint address="xml" behaviorConfiguration="xmlEndpointBehavior" binding="webHttpBinding" bindingConfiguration="xmlsBinding" name="xmlHttpsEndpoint" bindingName="Namespace.Service.XmlHttps" contract="Namespace.Web.WCF.IService" />
<endpoint address="" behaviorConfiguration="xmlEndpointBehavior" binding="webHttpBinding" bindingConfiguration="rawBinding" name="rawHttpEndpoint" bindingName="Namespace.Service.RawHttp" contract="Namespace.Web.WCF.IService" />
<endpoint address="" behaviorConfiguration="xmlEndpointBehavior" binding="webHttpBinding" bindingConfiguration="rawsBinding" name="rawHttpsEndpoint" bindingName="Namespace.Service.RawHttps" contract="Namespace.Web.WCF.IService" />
<endpoint address="web" binding="basicHttpBinding" bindingName="Namespace.Service" contract="Namespace.Web.WCF.IService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
This blog post has the solution: http://kimcuhoang.blogspot.be/2011/04/solving-raw-issue-with-wcf-and-content_13.html
Basically you have to override the default web message encoding
Create a custom mapper:
public class RawContentTypeMapper : WebContentTypeMapper
{
public override WebContentFormat GetMessageFormatForContentType(string contentType)
{
if (contentType.Contains("text/xml") || contentType.Contains("application/xml"))
{
return WebContentFormat.Raw;
}
else
{
return WebContentFormat.Default;
}
}
}
Then refer to it in the binding configuration:
<service behaviorConfiguration="NotificationServiceBehavior" name="AtlanticGateway.GatewayComponent.Services.NotificationService">
<endpoint behaviorConfiguration="web" binding="customBinding" bindingConfiguration="RawReceiveCapable" contract="AtlanticGateway.GatewayComponent.Message.INotificationService" />
<bindings>
<customBinding>
<binding name="RawReceiveCapable">
<webMessageEncoding webContentTypeMapperType="AtlanticGateway.GatewayComponent.RawContentTypeMapper, AtlanticGateway.GatewayComponent, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<httpTransport manualAddressing="true" maxReceivedMessageSize="524288000" transferMode="Streamed" />
...

"There was no endpoint listening" - Configuration Mismatch Perhaps?

I get
"There was no endpoint listening at https://localhost/BassCoastServices/GeneralUtilityService.svc that
could accept the message. This is often caused by an incorrect address
or SOAP action. See InnerException, if present, for more details."
when I call the GeneralUtilityService from the client side and
"There was no channel actively listening at 'https://laura-laptop/BassCoastServices/GeneralUtilityService.svc'.
This is often caused by an incorrect address URI. Ensure that the
address to which the message is sent matches an address on which a
service is listening."
shows up when I debug w3wp.
Is there some sort of tool I can use that will make sure a client and server config file line up?
If this is an easy fix, please see the below App and Web config files.
App.config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="Username" value="sampleuser"/>
<add key="Password" value="samplepassword"/>
<add key="basePath" value="C:\Temp"/>
</appSettings>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<bindings>
<wsHttpBinding>
<binding name="standardBinding" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" allowCookies="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="163840" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<reliableSession ordered="true" inactivityTimeout="01:00:00" enabled="false"/>
<security mode="TransportWithMessageCredential" >
<transport clientCredentialType="Certificate" proxyCredentialType="None" />
<message clientCredentialType="UserName" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="ClientCertificateBehavior">
<callbackDebug includeExceptionDetailInFaults="true"/>
<clientCredentials>
<clientCertificate findValue="localhost" x509FindType="FindByIssuerName" storeLocation="LocalMachine" storeName="My">
</clientCertificate>
</clientCredentials>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="https://localhost/BassCoastServices/GeneralUtilityService.svc" behaviorConfiguration="ClientCertificateBehavior" binding="wsHttpBinding" bindingConfiguration="standardBinding" contract="Adapt.WCF.IGeneralUtilityService" name="IGeneralUtilityServiceEndPoint">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</client>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
</startup>
</configuration>
Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
<add key="DatabaseConnectionString" value="Data Source=(local)\SQL2014;Initial Catalog=XIVICProduction;User ID=sa;Password=sameplepassword;MultipleActiveResultSets=True"/>
<add key="LogFilePath" value="C:\inetpub\wwwroot\Xivic\BassCoastServices\Log\Log.txt"/>
<add key="AllowMissingExternalIDs" value="true"/>
<!--No need to change-->
<add key="LogFileTypeLevel" value="Error"/>
<add key="SqlServerDateTimeStyle" value="103"/>
<add key="DatabaseType" value="Sql"/>
<add key="EnforceSecurityAtBusinessRulesLayer" value="false"/>
<add key="DateComparisonInaccuracy" value="35000"/>
<add key="CacheAccessItemsAtBusinessLayer" value="true"/>
<add key="CacheRecordsAtDataLayer" value="true"/>
<add key="SesionTimeout" value="1440"/>
</appSettings>
<system.serviceModel>
<services>
<!-- ENDPOINTS -->
<service name="IGeneralUtilityServiceEndPoint" behaviorConfiguration="UserNameBehaviour">
<endpoint binding="wsHttpBinding" contract="Adapt.WCF.IGeneralUtilityService" bindingConfiguration="wsHttpEndpointBinding"/>
</service>
</services>
<!-- BEHAVIOURS -->
<behaviors>
<serviceBehaviors>
<behavior name="UserNameBehaviour">
<serviceThrottling maxConcurrentCalls="2147483647" maxConcurrentInstances="2147483647" maxConcurrentSessions="2147483647" />
<serviceDebug includeExceptionDetailInFaults="True" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Adapt.WCF.Security.CustomUserNameValidator, Adapt.WCF" />
<serviceCertificate findValue="localhost" x509FindType="FindByIssuerName" storeLocation="LocalMachine" storeName="My">
</serviceCertificate>
</serviceCredentials>
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>
<!-- BINDINGS -->
<bindings>
<wsHttpBinding>
<binding name="wsHttpEndpointBinding">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" />
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "C:\inetpub\wwwroot\Xivic\BassCoastServices\Log\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
<!--startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/>
</startup-->
</configuration>
Calling WCF
_Channel = GetProxy<IGeneralUtilityService>();
_Channel.BeginTransaction(transactionId);
_Channel.CommitTransaction(transactionId);
public static T GetProxy<T>()
{
var channelFactory = new ChannelFactory<T>(string.Format("{0}EndPoint", typeof(T).Name));
channelFactory.Credentials.UserName.UserName = ConfigurationSettings.AppSettings["Username"];
channelFactory.Credentials.UserName.Password = ConfigurationSettings.AppSettings["Password"];
var workflowProxy = channelFactory.CreateChannel();
return workflowProxy;
}
Thanks in advance!
Update: I don't know what I did but now I'm getting
"Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost/BassCoastServices/GeneralUtilityService.svc. The client and service bindings may be mismatched."
Your problem is the way you create your channel factory. Some how it can not get the correct EndpointConfigurationName.
I'm not quite familiar on how to use only the EndpointConfigurationName as parameter in Channel Factory but you can try it this way:
var channelFactory = new ChannelFactory<T>("*", new EndpointAddress("https://localhost/BassCoastServices/GeneralUtilityService.svc"));
Well I don't know what the problem was but for anyone looking for a solution to this problem here are my web and app config files:
Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<!--Please configure-->
<!--Laura Local-->
<add key="DatabaseConnectionString" value="Data Source=(local)\SQL2014;Initial Catalog=XIVICProduction;User ID=sa;Password=samplepassword;MultipleActiveResultSets=True"/>
<!--No need to change-->
<add key="LogFilePath" value="C:\Temp\Log\log.txt" />
<add key="LogFileTypeLevel" value="Information" />
<add key="SqlServerDateTimeStyle" value="103" />
<add key="DatabaseType" value="Sql" />
<add key="EnforceSecurityAtBusinessRulesLayer" value="false" />
<add key="DateComparisonInaccuracy" value="35000" />
<add key="CacheAccessItemsAtBusinessLayer" value="true" />
<add key="CacheRecordsAtDataLayer" value="true" />
<!--Email Configuration-->
<!--add key="EmailAlertHost" value=""[INSERT="" HOST="" ADDRESS=""]/>
<add key="EmailAlertUsername" value=""[INSERT="" USERNAME=""]/>
<add key="EmailAlertPassword" value=""[INSERT="" PASSWORD=""] />
<add key="EmailAlertReplyToAddress" value=[INSERT REPLY TO ADDRESS] />
<add key="EmailAlertToAddress" value=""/>
<add key="EmailAlertCCAddress" value=""/>
<add key="EmailAlertSubject" value="*WARNING* - A Fatal Error Occurred # {0} - *WARNING*"/>
<add key="EmailAlertPriority" value="High"/-->
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
</startup>
<system.web>
<compilation debug="true"/>
</system.web>
<system.serviceModel>
<services>
<!--AssetInventoryService-->
<service name="Adapt.WCF.AssetInventory.AssetInventoryService" behaviorConfiguration="UserNameBehaviour">
<endpoint binding="customBinding" contract="Adapt.WCF.AssetInventory.AssetInventoryService" bindingConfiguration="UserNameBinding" />
</service>
<!--AssetValuationUtilityService-->
<service name="Adapt.WCF.AssetValuation.AssetValuationUtilityService" behaviorConfiguration="UserNameBehaviour">
<endpoint binding="customBinding" contract="Adapt.WCF.IAssetValuationUtilityService" bindingConfiguration="UserNameBinding" />
</service>
<!--CodeGenerationService-->
<service name="Adapt.WCF.CodeGeneration.CodeGenerationService" behaviorConfiguration="UserNameBehaviour">
<endpoint binding="customBinding" contract="Adapt.WCF.CodeGeneration.CodeGenerationService" bindingConfiguration="UserNameBinding" />
</service>
<!--CodeUtilityService-->
<service name="Adapt.WCF.CodeGeneration.CodeUtilityService" behaviorConfiguration="UserNameBehaviour">
<endpoint binding="customBinding" contract="Adapt.WCF.CodeGeneration.ICodeUtilityService" bindingConfiguration="UserNameBinding"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/CodeUtilityService.svc" />
</baseAddresses>
</host>
</service>
<!--DataSchemaService-->
<service name="Adapt.WCF.DataSchema.DataSchemaService" behaviorConfiguration="UserNameBehaviour">
<endpoint binding="customBinding" contract="Adapt.WCF.DataSchema.DataSchemaService" bindingConfiguration="UserNameBinding" />
</service>
<!--DataTransactionService-->
<service name="Adapt.WCF.DataTransaction.DataTransactionService" behaviorConfiguration="UserNameBehaviour">
<endpoint binding="customBinding" contract="Adapt.WCF.DataTransaction.DataTransactionService" bindingConfiguration="UserNameBinding" />
</service>
<!--GeneralUtilityService-->
<service name="Adapt.WCF.GeneralUtilityService" behaviorConfiguration="UserNameBehaviour">
<endpoint binding="customBinding" contract="Adapt.WCF.IGeneralUtilityService" bindingConfiguration="UserNameBinding"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/GeneralUtilityService.svc" />
</baseAddresses>
</host>
</service>
<!--SecurityService-->
<service name="Adapt.WCF.Security.SecurityService" behaviorConfiguration="UserNameBehaviour">
<endpoint binding="customBinding" contract="Adapt.WCF.Security.SecurityService" bindingConfiguration="UserNameBinding" />
</service>
<!--SyncService-->
<service name="Adapt.WCF.SyncService" behaviorConfiguration="UserNameBehaviour">
<endpoint binding="customBinding" contract="Adapt.WCF.ISyncService" bindingConfiguration="UserNameBinding" />
</service>
<!--SystemSetupService-->
<service name="Adapt.WCF.SystemSetup.SystemSetupService" behaviorConfiguration="UserNameBehaviour">
<endpoint binding="customBinding" contract="Adapt.WCF.SystemSetup.SystemSetupService" bindingConfiguration="UserNameBinding" />
</service>
<!--TaskManagementService-->
<service name="Adapt.WCF.TaskManagement.TaskManagementService" behaviorConfiguration="UserNameBehaviour">
<endpoint binding="customBinding" contract="Adapt.WCF.TaskManagement.TaskManagementService" bindingConfiguration="UserNameBinding" />
</service>
</services>
<!-- BEHAVIOURS -->
<behaviors>
<serviceBehaviors>
<behavior name="UserNameBehaviour">
<serviceThrottling maxConcurrentCalls="2147483647" maxConcurrentInstances="2147483647" maxConcurrentSessions="2147483647" />
<serviceDebug includeExceptionDetailInFaults="True" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Adapt.WCF.Security.CustomUserNameValidator, Adapt.WCF" />
<serviceCertificate findValue="localhost" x509FindType="FindByIssuerName" storeLocation="LocalMachine" storeName="My">
</serviceCertificate>
</serviceCredentials>
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>
<!-- BINDINGS -->
<bindings>
<customBinding>
<binding name="UserNameBinding" closeTimeout="23:00:00" openTimeout="23:00:00" receiveTimeout="23:00:00" sendTimeout="23:00:00">
<security authenticationMode="SecureConversation" requireSecurityContextCancellation="true">
<secureConversationBootstrap authenticationMode="UserNameForSslNegotiated">
</secureConversationBootstrap>
</security>
<textMessageEncoding>
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</textMessageEncoding>
<httpTransport transferMode="Buffered" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
</system.serviceModel>
<!--<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\temp\log\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>-->
</configuration>
App.config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="Username" value="dspec"/>
<add key="Password" value="samplepassword"/>
<add key="BasePath" value="c:\FileDrop"/>
</appSettings>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<bindings>
<wsHttpBinding>
<binding name="standardBinding" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" allowCookies="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="163840" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<reliableSession ordered="true" inactivityTimeout="01:00:00" enabled="false"/>
<security mode="Message">
<transport clientCredentialType="Certificate" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="ClientCertificateBehavior">
<callbackDebug includeExceptionDetailInFaults="true"/>
<clientCredentials>
<serviceCertificate>
<authentication certificateValidationMode="None"/>
</serviceCertificate>
</clientCredentials>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="http://localhost/BassCoastServices/GeneralUtilityService.svc" behaviorConfiguration="ClientCertificateBehavior" binding="wsHttpBinding" bindingConfiguration="standardBinding" contract="Adapt.WCF.IGeneralUtilityService" name="IGeneralUtilityServiceEndPoint">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</client>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
</startup>
</configuration>

Web Service Endpoint identity error

I have a problem with our web service. We didn't make the web service so we don't know what's really happening. At first, it works in our server but sometimes it doesn't which causes us to restart it. Then now, it shows error message:
Secure channel cannot be opened because security negotiation with the remote endpoint has failed. This may be due to absent or incorrectly specified EndpointIdentity in the EndpointAddress used to create the channel. Please verify the EndpointIdentity specified or implied by the EndpointAddress correctly identifies the remote endpoint.
But our web service is not even secured! Our web config is:
<configuration>
<connectionStrings>
<add name="DefaultConnection" connectionString="Server=;Database=;User ID=;Password=;Trusted_Connection=False;" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime executionTimeout="3600000" maxRequestLength="102400" />
</system.web>
<appSettings>
<add key="baseAddress" value="http://localhost:20088" />
<add key="timeout" value="120"/>
<add key="provider" value="System.Data.SqlClient" />
</appSettings>
<system.serviceModel>
<services>
<service name="H2WcfService.DataAccess" behaviorConfiguration="H2WcfServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:20088"/>
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="H2WcfService.IDataAccess" bindingConfiguration="DataAccess">
<identity>
<dns value="localhost:20088"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
<service name="H2WcfService.LoginService" behaviorConfiguration="H2WcfServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:20088"/>
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="H2WcfService.ILoginService" bindingConfiguration="Authentic">
<identity>
<dns value="localhost:20088"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
<service name="H2WcfService.LMSService" behaviorConfiguration="H2WcfServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:20088"/>
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" contract="H2WcfService.ILMSService" bindingConfiguration="LMSService">
<identity>
<dns value="localhost:20088"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="H2WcfServiceBehavior" >
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<wsHttpBinding>
<binding name="DataAccess" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="None">
<transport clientCredentialType="None" />
<message establishSecurityContext="false" />
</security>
</binding>
<binding name="Authentic">
<security mode="None">
<transport clientCredentialType="None" />
<message establishSecurityContext="false" />
</security>
</binding>
<binding name="LMSService">
<security mode="None">
<transport clientCredentialType="None" />
<message establishSecurityContext="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Finally found the answer! Basically, under Binding in System.Servicemodel of my asp.net application web.config, I should have added:
<security mode="None"/>
It was deleted because I was playing with the code for the web service authentication. Thank God I have multiple backups! Thanks guys! I'll update this as answered after two days.
We have fixed
Old Code
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" />
<message establishSecurityContext="false" />
</security>
New Code
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="false" />
</security>
Under Security tag, try this
<security mode="None">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true" establishSecurityContext="true" />
</security>

Categories