How to use netTcpBinding and netMsmqBinding together? - wcf

I am trying to use both tcp as well as msmq but it gives an error msmq doesn't support dual binding or it's not properly configured, how to solve this issue?
I have created two end points.
I tried to do something like this
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="Binding_Config" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:02:30">
<security mode="None">
<transport clientCredentialType ="None" protectionLevel="None"></transport>
<message clientCredentialType="None"/>
</security>
</binding>
</netTcpBinding>
<netMsmqBinding>
<binding name="ServiceBinding" durable="true" exactlyOnce="true" useActiveDirectory="false" receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:02:30" >
<security mode="None">
<transport
msmqAuthenticationMode="None"
msmqProtectionLevel="None"
/>
</security>
</binding>
</netMsmqBinding>
</bindings>
<services>
<service name="WCFLib.SignalService"
behaviorConfiguration = "SignalServiceMEXBehavior">
<endpoint address ="TradeSignalService"
binding="netTcpBinding"
contract="TradeServiceLib.ITradeSignalService" bindingConfiguration="Binding_Config"/>
<!-- Enable the MEX endpoint -->
<!-- Need to add this so MEX knows the address of our service -->
<endpoint address="net.msmq://localhost/private/FirstQueue" binding="netMsmqBinding" contract="TradeServiceLib.ITradeSignalService" bindingConfiguration="ServiceBinding"/>
<!--<endpoint address="mex" binding="netTcpBinding" contract="IMetadataExchange"/>-->
<host>
<baseAddresses>
<add baseAddress ="http://192.168.1.125:2344"/>
<add baseAddress ="net.tcp://192.168.1.125:2348"/>
</baseAddresses>
</host>
</service>
</services>
<!-- A behavior definition for MEX -->
<behaviors>
<serviceBehaviors>
<behavior name="SignalServiceMEXBehavior" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<connectionStrings>
<clear />
</connectionStrings>
</configuration>
I am not sure where I am wrong.
I don't know why but this site needs more text from me so typing this line, please ignore this I don't know why but this site needs more text from me so typing this line, please ignore this I don't know why but this site needs more text from me so typing this line, please ignore this I don't know why but this site needs more text from me so typing this line, please ignore this I don't know why but this site needs more text from me so typing this line, please ignore this

Those two bindings are very different. You need two endpoints for the same service exposed at different addresses and set up with different bindings.
See this MSDN article for more information on this.
As an example:
<service
name="Microsoft.ServiceModel.Samples.CalculatorService"
behaviorConfiguration="CalculatorServiceBehavior">
<!-- This endpoint is exposed at the base address provided by host:
http://localhost/servicemodelsamples/service.svc -->
<endpoint address=""
binding="basicHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
<!-- secure endpoint exposed at {base address}/secure:
http://localhost/servicemodelsamples/service.svc/secure -->
<endpoint address="secure"
binding="wsHttpBinding"
contract="Microsoft.ServiceModel.Samples.ICalculator" />
...
</service>

Related

WCF Hosted in IIS 7.0 Binding Issue

I have hosted a WCF Service on IIS7 by creating a WCFService Application Project Type.
In WCF Service Solution, there are two Project. 1) Actual *WCFService* *and 2) WCFService Application* for hosting it in IIS7.0
1) Actual WCFService Project. app.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="DHDocuments.DService">
<endpoint address="" binding="wsHttpBinding"
contract="DHDocuments.IDService" >
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/DHDocuments/DService/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
2) WCFService Application web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<services>
<service name="DHDocuments.DService">
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration=""
name="basic"
contract="DHDocuments.IDService"/>
</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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
In the IIS its being hosted. Its available at http://localhost:2004/DService.svc
Now Coming to the WCF Consuming Project,
I have added a Service Reference by Pointing to the http://localhost:2004/DService.svc. In my WCF Consuming client project this is the app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<client>
<endpoint address="http://localhost:2004/DService.svc"
binding="basicHttpBinding"
bindingConfiguration="basic1"
contract="WCFDHService.IDService"
name="basic" />
</client>
<bindings>
<basicHttpBinding>
<binding name="basic1" closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:10:00"
sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288"
maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8"
transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192"
maxArrayLength="16384" maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None"
proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName"
algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
This now complains:
The binding at system.serviceModel/bindings/basicHttpBinding does not have a configured binding named 'basic1'. This is an invalid value for bindingConfiguration
**
Can someone point what is being missed?
There is no problem when I have utilised wcf service directly by debug mode, without hosting it in IIS. I am sure, the binding config is getting error.
It appears that you have configured your services for metadata discovery with a mex endpoint:
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
Another endpoint in the service configuration is defined as wsHttpBinding:
<endpoint address="" binding="wsHttpBinding" contract="DHDocuments.IDService" >
I am guessing since mex is enabled the client proxy will generate a wsdl, however, you need to specify https if using transport security. Or add a endpoint for basicHttpBinding in your wcf service.
It seems like you are trying to access your service in the client proxy using a basicHttpBinding configuration but the service is not configured to accept or listen for such.

Silverlight 404 on service with SSL enabled

I've tried a lot of tips on this one but I cannot get it working. On the client I have:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="[binding_name]">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="/[service_name].svc"
binding="basicHttpBinding"
bindingConfiguration="[binding_name]"
contract="[contract_name]"
name="[endpoint_name]" />
</client>
</system.serviceModel>
</configuration>
And on the server:
...<service name="[service_name]">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="[binding_name]"
contract="[contract_name]"
name="[endpoint_name]"/>
<endpoint contract="IMetadataExchange"
binding="mexHttpsBinding"
address="mex" />
</service><behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors><bindings>
<basicHttpBinding>
<binding name="[binding_name]">
<security mode="Transport">
<transport clientCredentialType ="None"/>
</security>
</binding>
</basicHttpBinding>...
One potential clue is that when I navigate to https://[server_name]/[service_name].svc?wsdl, I see the location is correct on
<wsdl:import namespace="http://[namespace]" location="https://[server_name]/[service_name].svc?wsdl=wsdl0"/>
but incorrect on
<wsdl:port name="[binding_name]" binding="tns:[binding_name]">
<soap:address location="http://[machine_name]/[service_name].svc"/>
</wsdl:port>
Notice location="http://[machine_name]/[service_name].svc" Is that expected? If not, what could be the problem?
I've also made sure that [service_name] in the server configuration is the FQN of the service implementation. Everything worked as expected before I enabled SSL on the server and changed the security mode to transport, etc.
The problem in my case was the fact that though the service_name in <service name="[service_name]"> was the correct FQN of the service implementation, it did not match the Service attribute in the *.svc file. In that case it seems that WCF creates a default name for the endpoint, which is something like BasicHttp_service_name. That worked until SSL was enabled and was looking for the endpoint with a URL starting with https.
As for the machine_name issue, it was because I didn't set the host name for https in the IIS site bindings.

Accessing WCF service on AppHarbor via https

I'm trying to secure my WCF service using transport security model. I've successfully deployed my service to AppHarbor. But I'm getting the following exception when I try to access service page:
[InvalidOperationException: Could not find a base address that matches scheme https for the endpoint with binding BasicHttpBinding. Registered base address schemes are [http].] ...
I haven't uploaded any certificates, just using piggyback SSL there. I've downloaded the build and deployed it on my machine. It works fine.
Here is my system.serviceModel section of web.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="AuthService.AuthServiceBehavior" name="AuthService.AuthService">
<host>
<baseAddresses>
<add baseAddress="https://auth.apphb.com/AuthService.svc" />
</baseAddresses>
</host>
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="TransportSecurity" contract="AuthService.IAuthService" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="AuthService.AuthServiceBehavior">
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
I've already tried this Hosting a WCF Web API app on AppHarbor?
Can somebody please explain me what I'm doing wrong?
This issue frequently appear when you communicate with the wcf web service thru the LB (AppHarbor one of the example of it).
You should know several things about such kind of communications.
1) Communication between yours client application and LB is secured (https is in use). So you should leverage security binding on the client side.
<basicHttpBinding>
<binding name="BasicHttpBinding_IAuthService">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
2) Communication between LB and web-front uses http, so server binding should be basicHttpBinding without extra configuration.
<endpoint binding="basicHttpBinding" contract="AuthService.IAuthService" />
Summarizing all that stuff we have
Client
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IAuthService">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://auth.apphb.com/AuthService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAuthService"
contract="AuthService.IAuthService" name="BasicHttpBinding_IAuthService" />
</client>
</system.serviceModel>
</configuration>
Server
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<protocolMapping>
<add scheme="http" binding="basicHttpBinding" />
</protocolMapping>
<bindings>
<basicHttpBinding/>
</bindings>
<services>
<service behaviorConfiguration="AuthService.AuthServiceBehavior" name="AuthService.AuthService">
<endpoint binding="basicHttpBinding" contract="AuthService.IAuthService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="AuthService.AuthServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Your approach is not going to work right off the bat. This is because SSL is terminated at the load balancers and the app servers see http traffic. You can read more about AppHarbor load balancers here.
You might be able to fool WCF with this module.
There are also some hints in this discussion: http://support.appharbor.com/discussions/problems/829-transportwithmessagecredential-https-ssl

Could not find a base address that matches scheme https for the endpoint with binding WebHttpBinding. Registered base address schemes are [http]

I know already Many of them getting this same error. I tried all the possible answers given here but i am still getting this error.
My Web.config for the service.
<serviceBehaviors>
<behavior name="AjaxServiceHttpsBehavior">
<serviceMetadata httpsGetEnabled ="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="AjaxServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="AjaxService" behaviorConfiguration="AjaxServiceHttpsBehavior">
<host>
<baseAddresses>
<add baseAddress="https://servername/websitefolder" />
</baseAddresses>
</host>
<endpoint address="" behaviorConfiguration="AjaxServiceAspNetAjaxBehavior" binding="webHttpBinding" bindingConfiguration="webHttpsBinding" contract="AjaxService" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webHttpsBinding">
<security mode="Transport"></security>
</binding>
</webHttpBinding>
<basicHttpBinding>
The service is located at "https://servername/websitefolder/AjaxService.svc" and ssl is configured correctly.
is my Base Address is wrong? I have only one End point for this service. I tried all the possible combinations but still I am getting this error.
I ran into the same issue with wsHttpBinding, and found it wasn't a problem with my base address at all but what I had defined in my element
<wsHttpBinding><binding name="wsHttpBinding_Administration">
<security mode="Message"> <!-- changed this to "message" -->
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
Check bindings of your website inside of IIS. https binding should be added there.

How do you configure a WCF service with two endpoints to use a different ListenUri for each endpoint?

I have a WCF Service which exposes an endpoint using the webHttpBinding and is consumed by both WPF and ASP.NET applications. Everything works great.
I am now attempting to consume the service from Windows Phone (WP7). However, as the .NET Framework hasn't quite caught up to WP7 yet, the System.ServiceModel.Web namespace is unavailable with the result that the webHttpBinding doesn't work in WP7.
Now, on my service, if I switch the webHttpBinding out for a basicHttpBinding, the phone application works.
I do not want to have to rework my WPF and ASP.NET applications to use the basicHttpBinding though.
I understand that WCF is capable of supporting multiple bindings and I have attempted to configure and run the service so that it exposes endpoints for both webHttpBinding and basicHttpBinding. The service appears to start up fine. However, the WPF & ASP.NET applications are unable to access it. And when I attempt to create a Service Reference in the WP7 application I get the following message:
A binding instance has already been associated to listen URI
'http://localhost:1726/GeneralService.svc'. If two endpoints want to
share the same ListenUri, they must also share the same binding object
instance. The two conflicting endpoints were either specified in
AddServiceEndpoint() calls, in a config file, or a combination of
AddServiceEndpoint() and config.
A colleague and I have played around with a variety of changes to the baseAddress, address, and listenUri attributes without any luck. We are now at the point of just trial and error which isn't proving to be very effective.
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="generalBasic" />
</basicHttpBinding>
<webHttpBinding>
<binding name="general" maxReceivedMessageSize="2147483647">
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" />
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="MyProject.GeneralService">
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="generalBasic"
contract="MyProject.Contracts.IGeneralService" />
<endpoint behaviorConfiguration="web"
binding="webHttpBinding"
bindingConfiguration="general"
contract="MyProject.Contracts.IGeneralService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:1726/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
Just specify the address attribute with a value for either basic or webhttp endpoint that would distinguish its address. Ex:
<endpoint behaviorConfiguration="web" address="rest" binding="webHttpBinding" bindingConfiguration="general" contract="MyProject.Contracts.IGeneralService" />
should resolve your problem
When defining your endpoints for the first one you are specifying address="" and for second you dont have any value(So even for this one we will have address as "")
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="generalBasic"
contract="MyProject.Contracts.IGeneralService" />
<endpoint behaviorConfiguration="web"
binding="webHttpBinding"
bindingConfiguration="general"
contract="MyProject.Contracts.IGeneralService" />
So in that case when we specify address as empty it will take default base address.
So try to specify some value for anyone of the endpoints. So that we will have different address for these 2 endpoints.
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="generalBasic"
contract="MyProject.Contracts.IGeneralService" />
<endpoint behaviorConfiguration="web" address="WP7Service"
binding="webHttpBinding"
bindingConfiguration="general"
contract="MyProject.Contracts.IGeneralService" />
So our new endpoints address are:
http://localhost:1726/GeneralService.svc
http://localhost:1726/GeneralService.svc/WP7Service
For usage service on WP you should expose your service with Rest, Soap or OData endpoints. In the link below it is quite clear described how to expose WCF RIA for such purposes: Exposing WCF (SOAP\WSDL) Services
It works great for me.
What I was missing was protocolMapping for both endpoints:
<configuration>
<!--...-->
<system.serviceModel>
<!--...-->
<protocolMapping>
<add binding="basicHttpBinding" scheme="http" bindingConfiguration="BasicHttpBindingConfiguration"/>
<add binding="basicHttpsBinding" scheme="https" bindingConfiguration="SecureHttpBindingConfiguration"/>
</protocolMapping>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBindingConfiguration" />
<binding name="SecureHttpBindingConfiguration" >
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="Namespace.ServiceName">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBindingConfiguration"
contract="Namespace.IServiceName" />
</service>
<service name="Namespace.ServiceName">
<endpoint address="" binding="basicHttpsBinding" bindingConfiguration="BasicHttpsBindingConfiguration"
contract="Namespace.IServiceName" />
</service>
</services>
<!--...-->
</system.serviceModel>
<!--...-->
</configuration>