WCF timeouts in SOME solutions - wcf

The problem is that when I create a new solution in VS2012 and add service reference of wcf, everything works fine. However, when I add the same service reference to one of my projects, the methods receive timeout exception. The problem might be that when I add the reference to my project, visual studio didn't create the codes until I uncheck the option "Reuse types in referenced assemblies". I checked configuration files but see no difference at all. I include a part of config file anyway:
<system.serviceModel>
<client>
<endpoint address="url"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
contract="NewsBannersCampaignService.IService" name="BasicHttpBinding_IService" />
</client>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService" />
</basicHttpBinding>
<wsHttpBinding>
<binding name="DefaultBinding">
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="DefaultBehavior" name="project.Services.Integration">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="DefaultBinding" name="Integration" contract="project.Services.IIntegration" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Edit: For anyone that may have this problem; the problem in my case was I forgot to delete my defaultProxy setting in config file. After deleting it everything worked fine. I just deleted
<system.net>
<defaultProxy>
<proxy proxyaddress="http://address" bypassonlocal="True" />
</defaultProxy>
</system.net>

Related

How to use netTcpBinding and netMsmqBinding together?

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>

WCF service: The HTTP request is unauthorized with client authentication scheme 'Negotiate'

I have a WCF client in a VS2012 project that has the configuration:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="myServiceBehaviour">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpEndpointBinding">
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service behaviorConfiguration="myServiceBehaviour"
name="xxx.Web.Mvc.Client.Services.MyService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpointBinding" name="BasicHttpEndpoint" contract="xxx.Wcf.IMyService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Within IIS 7.5, the service is set to use Windows authentication.
I'm using basicHttpBinding over HTTPS. My requirements are SSL, but I've ended up using Windows authentication to get it to work.
I have a quick and dirty console application with the following config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpEndpoint">
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://dev.xxxx.local/xxxx.Web.Mvc.Client/services/MyService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpoint"
contract="MyService.IMyService" name="BasicHttpEndpoint" />
</client>
</system.serviceModel>
This works fine, like a dream.
The same configuration (I thought) in a VB application:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpEndpoint" sendTimeout="10:00:00"> <!-- See point 1 below -->
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://xxxx.inter.local/xxxx.Web.Mvc.Client/services/MyService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpoint"
contract="MyService.IMyService" name="BasicHttpEndpoint" />
</client>
Doesn't work, instead I get:
MessageSecurityException: The HTTP request is unauthorized with client
authentication scheme 'Negotiate'. The authentication header received
from the server was 'Negotiate
oXIwcKADCg....igAwIBAaERMA8bDWlvbXZuZWRkZXYwMiQ='.
The service is clearly fine, it's just the client (and specifically the web site client) that is struggling.
Seemingly, the server is rejecting the authorisation from the web site client. The Negotiate response includes the token, I've ommitted for obvious reasons here, but you can see the structure.
How can I get this working? With the only requirement being it needs to be over SSL. I'd prefer to send credentials, but I'm not bothered. I didn't get very far using anonymous, anyway.
Points:
The sendTimeout setting is applied because for some reason when being called remotely from the web site client, execution takes over 1 minute and times out.
by this: http://blogs.msmvps.com/alvin/2008/11/14/net-3-5-sp1-breaking-change-to-wcf/
you may need to add this block to your endpoint-identity node
<servicePrincipalName value=""/>
turning it to:
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpEndpointBinding" name="BasicHttpEndpoint" contract="xxx.Wcf.IMyService">
<identity>
<dns value="localhost" />
<servicePrincipalName value=""/>
</identity>
</endpoint>

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>

Unable to access WCF Service from Client machine

Unable to access WCF Service from Client machine
I have three projects : WCF Service (VS-2008), Windows Service (VS-2008), Client (VS-2005)
The WCF service has netTcpBinding
This service is hosted as a windows service and not on IIS
The base address for both the service (WCF and Windows) is
net.tcp://localhost:8010/WCFService.Service1/
Now when i add a service reference to the client project which is on VS-2005, It updates my app.config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="netTcpEndPoint" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" listenBacklog="10"
maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10"
maxReceivedMessageSize="65536">
<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="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:8010/WCFService.Service1/"
binding="netTcpBinding" bindingConfiguration="netTcpEndPoint"
contract="Client.Service1.IService1"
name="netTcpEndPoint">
<identity>
<servicePrincipalName value="host/server17.domain.com" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
And adds Service1.map file as
<?xml version="1.0" encoding="utf-8"?>
<ServiceReference>
<ProxyGenerationParameters
ServiceReferenceUri="net.tcp://server17:8010/WCFService.Service1/"
Name="Service1"
NotifyPropertyChange="False"
UseObservableCollection="False">
</ProxyGenerationParameters>
<EndPoints>
<EndPoint
Address="net.tcp://localhost:8010/WCFService.Service1/"
BindingConfiguration="netTcpEndPoint"
Contract="Client.Service1.IService1"
>
</EndPoint>
</EndPoints>
</ServiceReference>
When I call any of the service methods I get an error stating
Could not connect to net.tcp://localhost:8010/WCFService.Service1/.
The connection attempt lasted for a time span of 00:00:02.0063936. TCP
error code 10061: No connection could be made because the target
machine actively refused it 127.0.0.1:8010.
At least it should be net.tcp://server17:8010/WCFService.Service1/
I have already tried to replace localhost with server17 in the client project... but no luck
What should I change to make it working? please help.
This is my WCF Service's App.config which is same as windows service's
app.config : as requested by Tim
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="WCFService.ServiceBehavior"
name="WCFService.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
name="netTcpEndPoint" contract="WCFService.IService1" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
name="mexTcpEndPoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8010/WCFService.Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WCFService.ServiceBehavior">
<serviceMetadata httpGetEnabled="False" />
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
At a guess I'd check three things:
When you add the service reference to your client, are you adding it from net.tcp://localhost:8010/WCFService.Service1/, or are you adding it from net.tcp://server17:8010/WCFService.Service1/?
If you're adding it from server17, try using the fully qualified name of the server - i.e., server17.mydomain.com or whatever it is.
The connection error is probably related to the endpoint address you're using - the client is passing in a serverPrincipalName of "host/server17.domain.com", but you're attempting to connect to localhost.
No guarantees any of the above are the root cause, but it gives you a place to start.
EDIT
You specify the locahost in the baseAddress element, but you don't specify anything in the address attribute of the endpiont element. That's probably why it's still going to localhost.
Modify the config file for your service to either change the baseAddress to:
<baseAddresses>
<add baseAddress="net.tcp://server17:8010/WCFService.Service1/" />
</baseAddresses>
or drop the baseAddresses and specify the address in your endpoint:
<endpoint address="net.tcp://server17:8010/WCFService.Service1/"
binding="netTcpBinding"
bindingConfiguration=""
name="netTcpEndPoint"
contract="WCFService.IService1" />
Give that a try.

webHttpBinding using webMessageEncoding: how to configure?

I have a REST WCF service. Its using a webHttpBinding and the configuration looks like this:
<service name="IndexingService.RestService" behaviorConfiguration="IndexingService.Service1Behavior">
<endpoint
address=""
binding="webHttpBinding"
bindingConfiguration="CustomMapper"
contract="IndexingService.IIndexingService"
behaviorConfiguration="webby"/>
</service>
The CustomMapper is used to apply a custom WebContentTypeMapper, which I tried to configure like this:
<binding name="CustomMapper">
<webMessageEncoding webContentTypeMapperType="IndexingService.CustomContentTypeMapper, IndexingService" />
<httpTransport manualAddressing="true" />
</binding>
But I cannot figure out where in my web.config I should insert these lines:
If I put these lines below I get an error, because webMessageEncoding is not a recognized element.
If I put the lines below a custom binding tag, I get an error that wsHttpBinding does not have a CustomMapper defined!?
Can somebody explain how to use a custom type mapper together with webHttpBinding?
If you define a complete custom binding (as you do here with CustomMapper):
<binding name="CustomMapper">
<webMessageEncoding webContentTypeMapperType=
"IndexingService.CustomContentTypeMapper, IndexingService" />
<httpTransport manualAddressing="true" />
</binding>
then you need to use that custom binding in your service endpoint - not webHttpBinding! This config section does not define just a bindingConfiguration!
Try this config here:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomMapper">
<webMessageEncoding webContentTypeMapperType=
"IndexingService.CustomContentTypeMapper, IndexingService" />
<httpTransport manualAddressing="true" />
</binding>
</customBinding>
</bindings>
<services>
<service name="IndexingService.RestService"
behaviorConfiguration="IndexingService.Service1Behavior">
<endpoint
address=""
binding="customBinding"
bindingConfiguration="CustomMapper"
contract="IndexingService.IIndexingService"
behaviorConfiguration="webby"/>
</service>
</services>
</system.serviceModel>
Marc