I have 1 service and multiple endpoints as shown below. I want to have a general behaviour and overwrite my wshttpbinding with another behaviour but when I try that I receive error tells me
Parser Error Message: There is no endpoint behavior named 'CredentialValidator'.
what am I doing wrong?
<services>
<service name="myservice.Service.myserviceService" behaviorConfiguration="myserviceBehaviour">
<host>
<baseAddresses>
<add baseAddress="https://localhost:44300/myService.svc"/>
<!--<add baseAddress="http://localhost:54941/myService.svc"/>-->
<!--<add baseAddress="http://myservicewcf.myurl-staging.com/myService.svc"/>-->
<add baseAddress="https://myservice.myurl-staging.com/myService.svc"/>
<add baseAddress="https://myservice.production.com/myService.svc"/>
<!--<add baseAddress="https://myservicetest.myurl-staging.com/myService.svc"/>-->
</baseAddresses>
</host>
<endpoint name="myserviceSoap12Endpoint" address="soap12" binding="customBinding" bindingConfiguration="soap12selfBinding" contract="myservice.Service.ImyserviceService" behaviorConfiguration="CredentialValidator" />
<endpoint name="myserviceWSHttpEndpoint" address="ws" binding="wsHttpBinding" bindingConfiguration="myserviceWSHttpBinding" contract="myservice.Service.ImyserviceService"/>
<endpoint name="myserviceBasicHttpEndpoint" address="" binding="basicHttpBinding" bindingConfiguration="myserviceBasicHttpBinding" contract="myservice.Service.ImyserviceService"/>
<!--<endpoint name="myserviceBasicHttpEndpoint2" address="" binding="basicHttpBinding" bindingConfiguration="myserviceBasicHttpBinding" contract="myservice.Service.ImyserviceService2"/>-->
<endpoint name="myserviceMexEndpointHttps" address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name ="CredentialValidator">
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug
includeExceptionDetailInFaults="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="myservice.Service.CustomUserNameValidator, myservice"/>
</serviceCredentials>
</behavior>
<behavior name="myserviceBehaviour">
<useRequestHeadersForMetadataAddress/>
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
Try putting your CredentialValidatorbehavior in <endpointBehaviors> tags instead of <serviceBehaviors>.
Because the exception message clearly states that there is not any endpointBehavior with that name. So give it one! Like this:
<behaviors>
**<endpointBehaviors>**
<behavior name ="CredentialValidator">
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
**</endpointBehaviors>**
<serviceBehaviors>
<behavior name="myserviceBehaviour">
<useRequestHeadersForMetadataAddress/>
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
Related
When calling service url https://example.com/TestService.svc I am getting the below 2 URLs but when I am trying to click on WSDL then it is not working.
WSDL URLs
http://example.com/TestService.svc?wsdl -- NOT WORKING
http://example.com/TestService.svc?singleWsdl -- NOT WORKING
Manually change http to https
https://example.com/TestService.svc?wsdl -- WORKING
https://example.com/TestService.svc?singleWsdl -- WORKING
Client Config
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</client>
<behaviors>
<serviceBehaviors>
<clear/>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0" />
Main Service Config
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<clear />
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0">
<serviceActivations>
<clear />
<add factory="DataServicesHost.UnityServiceHostFactory" relativeAddress="TestService.svc" service="TestService.Service" />
</serviceActivations>
</serviceHostingEnvironment>
Service Consuming
var customHeader = new MessageHeader<Security>(security);
var tempHeader = customHeader.GetUntypedHeader("Security", "http://tempuri.org/");
var client = new ServiceClient();
using (var scope = new OperationContextScope(client.InnerChannel))
{
OperationContext.Current.OutgoingMessageHeaders.Add(tempHeader);
objDataRequest = client.DataRequest("test");
}
From the above configuration, we can infer that it belongs to the client-side. However, the WSDL feature of the WCF service is set up on the server-side. It is controlled by the ServiceMetadata section.
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
Therefore, if we want to have the HTTP protocol of WSDL feature working, we need to enable it on the server-side and apply the service behavior in the service section(the endpoint should be within the service section instead of client section).
<system.serviceModel>
<services>
<service name="WcfService3.Service1" behaviorConfiguration="sb">
<endpoint address="" binding="basicHttpBinding" contract="WcfService3.IService1"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="sb">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
Feel free to let me know if there is anything I can help with.
I have this WCF service with a SOAP endpoint and I'm succesfully exposing both methods with the following code/config:
Service Contract
[ServiceContract]
public interface IService
{
[OperationContract]
string TestConn();
[OperationContract]
string AddRecord();
}
Web.config
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="WSADPITG.Service" behaviorConfiguration="ServiceBehavior">
<endpoint binding="basicHttpBinding" contract="WSADPITG.IService" address="" name="WSADPITG" />
<endpoint binding="mexHttpBinding" contract="IMetadataExchange" address="mex" />
</service>
</services>
Is it possible to add a REST endpoint to expose ONLY TestConn method? What changes in code/config?
You should separate contracts,because single service can have single behavior.Hence two services should be host in your single web.config file.
WCF REST Service
[ServiceContract]
public interface IService
{
[OperationContract]
[WebGet]
string TestConn();
}
Now the configuration file.
<system.serviceModel>
<behaviors>
<serviceBehaviors >
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information, set the values below to false 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="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="ServiceClassNamespace.YourServiceClasImplementation" behaviorConfiguration="ServiceBehavior">
<endpoint binding="webHttpBinding" contract="ServiceClassNamespace.IService" behaviorConfiguration="web">
</endpoint>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Pure WCF Service
[ServiceContract]
public interface IService2
{
[OperationContract]
string AddRecord();
}
Your above mentioned web.config must be appended to the existing(WCF REST) config file.
<system.serviceModel>
<behaviors>
<serviceBehaviors >
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information, set the values below to false 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="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="ServiceClassNamespace.YourServiceClasImplementation" behaviorConfiguration="ServiceBehavior">
<endpoint binding="webHttpBinding" contract="ServiceClassNamespace.IService" behaviorConfiguration="web">
</endpoint>
</service>
<service name="WSADPITG.Service" behaviorConfiguration="ServiceBehavior">
<endpoint binding="basicHttpBinding" contract="WSADPITG.IService2" address="" name="WSADPITG" />
<endpoint binding="mexHttpBinding" contract="IMetadataExchange" address="mex" />
<host>
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<services>
<service name="WcfServiceApplication.WallService" behaviorConfiguration="mex" >
<host>
<baseAddresses>
<add baseAddress="net.pipe://localhost:10042/"/>
</baseAddresses>
</host>
<endpoint address="WallService.svc"
binding="netNamedPipeBinding" bindingConfiguration="basic" name="Basic"
contract="WcfServiceApplication.IWallService"></endpoint>
<endpoint address="mex"
binding="mexNamedPipeBinding"
contract="IMetadataExchange"></endpoint>
</service>
</services>
<bindings>
<netNamedPipeBinding>
<binding name="basic"></binding>
</netNamedPipeBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="mex">
<serviceMetadata httpGetEnabled="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
I have found the solution by troubleshooting and have resolved it.
Service should be hosted in a process and then be called.
I keep getting the page when I browse to my svc file that metadata publishing is not turned on but I have done everything for it. Here's my web.config. What am I doing wrong?
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="AlphaFrontEndSiteASP.TestsServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
<behavior name="AlphaFrontEndSiteASP.Services.TestsService">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MetadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="AlphaFrontEndSiteASP.Services.TestsService" behaviorConfiguration="MetadataBehavior">
<endpoint address="" behaviorConfiguration="AlphaFrontEndSiteASP.TestsServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="AlphaFrontEndSiteASP.Services.TestsService" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
</service>
</services>
</system.serviceModel>
This is similar to other Stack postings, but slightly different in that I am only hosting a single wsHttp endpoint (and the mex). When I leave the httpsGetUrl empty, it shows the server name instead of the public uri that I need (for the wsdl)
Here is the important part of the config.
<service behaviorConfiguration="myServiceBehaviors" name="WebApplication1.Service1">
<clear/>
<endpoint behaviorConfiguration="flatwsdl" address="mex" binding="mexHttpsBinding" bindingConfiguration="mexHttpsBinding"
contract="IMetadataExchange" listenUriMode="Explicit">
</endpoint>
<endpoint behaviorConfiguration="flatwsdl" address="wsHttp" binding="wsHttpBinding" bindingConfiguration="wsHttpBindingConfig"
contract="WebApplication1.IService1" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="myServiceBehaviors">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpsGetEnabled="true" httpsGetUrl="https://mydomain.com/integration/Service1.svc" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="flatwsdl">
<wsdlExtensions />
</behavior>
</endpointBehaviors>
</behaviors>
any suggestions?
If you want the public URI, you should use the <useRequestHeadersForMetadataAddress> behavior in your service behavior, that's exactly what this behavior is for.
<behavior name="myServiceBehaviors">
<useRequestHeadersForMetadataAddress />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpsGetEnabled="true" />
</behavior>