wsHttpBinding (with https and aspNetCompatibilityEnabled for routing) metadata error 302 - wcf

I am working on a WCF service which runs along with ASP.NET MVC 2 application with https port which have been configured using webMatrix-ssl certificate. The service is running perfectly in the browser and could download wsdl as well. But when am trying to load the service into wcftestclient tool and as well as my own client, getting the below error.
Error: Cannot obtain Metadata from 'localhost:44300/MyService' If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: localhost:44300/MyService Metadata contains a reference that cannot be resolved: 'localhost:44300/MyService'. The remote server returned an unexpected response: (302) Found. Too many automatic redirections were attempted.HTTP GET Error URI: localhost:44300/MyService There was an error downloading 'localhost:44300/MyService'. The request failed with the error message:--"
I had added the attribute aspNetCompatibilityEnabled="true" for wcf service routing, if that attribute has been removed all works fine. Initially this service has been configured with basicHttpBinding & had this same issue. After reading this article, I have changed to wshttpBinding as suspected binding could also be the problem, still am getting the same issue, below is my web.config.
Could anyone of you please help me to repair this?
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="ExceptionBehavior" type="ServiceExceptionHander.ExceptionHandlerBehaviorExtension, ServiceExceptionHandler" />
</behaviorExtensions>
</extensions>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
<ExceptionBehavior />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="ServiceImplementation.MyService" behaviorConfiguration="ServiceBehavior">
<endpoint binding="wsHttpBinding" bindingConfiguration="securityBinding" contract="ServiceContracts.IMyServiceContracts"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="securityBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true">
<serviceActivations>
<add factory="System.ServiceModel.Activation.ServiceHostFactory" service="ServiceImplementation.MyService" relativeAddress="MyService.svc"/>
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>

Related

There was no end point listening at... error for wcf service

I know there are lot of posts for this issue and I tried solutions from most of them but nothing seems to work.
I have a WCF service which was working fine in the Dev box when hosted on IIS and I moved this to the UAT box app server and I am able to access it and test if from the test client. So I now hosted my MVC application on the web server and from the web server browser I am able to access the service but when I run my web application which consumes the service it throws the following error.
Error Detail:- There was no endpoint listening at http://servername/AC.IS.BLService/CustService
.svc that could accept the message. This is often caused by an incorrect
address or SOAP action. See InnerException, if present, for more details.
Error TargetSite:- ACL.IS.BLWebSite.ViewModels.HomeAccountStatusViewModel
ValidateLogin(ACL.IS.BLWebSite.ViewModels.HomeAccountStatusViewModel)
Inner Exception:- System.Net.WebException: The remote server returned an
error: (404) Not Found. at System.Net.HttpWebRequest.GetResponse() at
System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannel
Request.WaitForReply(TimeSpan timeout)
So,I tried hosting the service and the web application together on the same server and I still have the same problem. The following are my config files for both the service and client
Client.config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ICustomerService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://servername/ACL.IS.BLService/CustService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICustService"
contract="BLService.ICustService" name="BasicHttpBinding_ICustService" />
</client>
</system.serviceModel>
Server Config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ICustService" />
</basicHttpBinding>
</bindings>
<services>
<service name="ACL.IS.BL_WebServices.CustService" behaviorConfiguration="mexBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/"/>
</baseAddresses>
</host>
<endpoint address="CustService" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICustService" contract="ACL.IS.BL_WebServices.ICustService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false"
multipleSiteBindingsEnabled="true" />
</system.serviceModel>
its a windows 2012 server. IIS 8.5. Could somebody please help.
Just to mention..there is a firewall as well..does it have something to do with port numbers ?
Your server config says that it listens on port 8080:
baseAddress="http://localhost:8080/"
while client connects to port 80:
address="http://servername/ACL.IS.BLService/CustService.svc"
I think they should match.
You appear to have a contract mismatch.
Client;
contract="BLService.ICustService"
Server;
contract="ACL.IS.BL_WebServices.ICustService"
These need to match

Wcf custom userNamePasswordValidationMode doesn't work at IIS express

I tried to make a secure wcf with custom userNamePasswordValidationMode service but I confronted some problems(for three days). My setup environment is visual studio 2012, .net 4.0, IIS Express. My service model in host is:
<system.serviceModel>
<bindings >
<wsHttpBinding>
<binding maxReceivedMessageSize="65536" name="WsHttpBinding_ISurveyService">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
<readerQuotas maxArrayLength="65536"
maxBytesPerRead="65536"
maxStringContentLength="65536"/>
</binding>
</wsHttpBinding>
</bindings>
<services>
<!--name= "namespace.serviceClass"-->
<service name="Rids.Services.SurveyService" behaviorConfiguration="Rids.WcfHost.ServiceBehavior" >
<!--contract= "namespace.serviceClass"-->
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="WsHttpBinding_ISurveyService"
contract= "Rids.Services.ISurveyService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="https://localhost" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Rids.WcfHost.ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
<serviceDebug httpHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="None" />
</clientCertificate>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="Rids.WcfHost.ServiceUserValidator,Rids.WcfHost"/>
<!--Specify the Certificate-->
<serviceCertificate findValue="rids_2014.04.15"
storeLocation="LocalMachine"
x509FindType="FindBySubjectName"
storeName="My"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
When I want to add this service to client, it can not read the metadata and gave the error below:
There was an error downloading 'https://localhost:44300/SurveyService.svc/_vti_bin/ListData.svc/$metadata'.
Unable to connect to the remote server
Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı 127.0.0.1:44300
Metadata contains a reference that cannot be resolved: 'https://localhost:44300/SurveyService.svc'.
There was no endpoint listening at https://localhost:44300/SurveyService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
Unable to connect to the remote server
Hedef makine etkin olarak reddettiğinden bağlantı kurulamadı 127.0.0.1:44300
If the service is defined in the current solution, try building the solution and adding the service reference again.
--
But if I delete name tag from behavior(name="Rids.WcfHost.ServiceBehavior" part) and behaviorConfiguration tag from service (behaviorConfiguration="Rids.WcfHost.ServiceBehavior" part); then I can add the service(https://localhost:44300/SurveyService.svc) to client without error. Also this doesn't solve my problem.
After adding service to client, client service model was like below:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ISurveyService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:11067/SurveyService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISurveyService"
contract="Survey.ISurveyService" name="BasicHttpBinding_ISurveyService" />
</client>
</system.serviceModel>
The problems I saw is:
Client service model sees basicHttpBinding although my service binding configuration is wsHttpBinding.
Client service model doesn't see ssl address although I added the service in the path: https://localhost:44300/SurveyService.svc.
I can not add the service to client if service has the behaviorConfiguration tag and behavior has name tag in host configuration.
Custom userNamePasswordValidationMode doesn't work and even if I add service to client without error, service doesn't see validation class or validation method. It works without validation.
Note: Service host project property of 'SSL Enabled' is True; and in project configuration project url is set to https://localhost:44300/.
I've encountered problems in problems. Any advice or solution? Thanks in advance.
I learned how to solve this problem. I made it using EditWcfConfiguration tool in visual studio 2012 as explained below.
Firstly, set property of 'SSL Enabled' as true in host project properties. Under this property automatically ssl url will be generated(such as 'https://localhost:44300/') Then, right click host project and select properties. In project properties Web tab, check 'Use Local IIS Web server' then check 'Use IIS Express'
--
In host project WebConfig, right click then select EditWcfConfiguration:
In EditWcfConfiguration firstly add service, then add a binding for endpoint of service, then add a behavior for service.
1- Add Service
Browse service type at host's bin folder
Select communication mode as HTTP
Select Advanced Web Service interoperability as Simplex communication
Leave the address blank
After adding behavior configuration; select BehaviorConfiguration
After adding binding configuration; open end point of service then, select binding(customBinding) and bindingConfiguration
2- Add a custom binding
Rename binding to use in service's BehaviorConfiguration property (such as 'custom_binding').
Add security, httpsTransport tags.
Select 'AuthenticationMode' as 'UserNameOverTransport' under security tag.
3- In Advanced/Service Behaviors folder, add new service behavior configuration
Rename behavior to use in service end point's BindingConfiguration property (such as safe_behavior).
Add serviceCredentials, serviceMetadata, serviceDebug tags.
For serviceCredentials tag properties:
a-) Select customUserNamePasswordValidatorType as your validator class and its namespace (such as: 'Rids.WcfHost.ServiceUserValidator, Rids.WcfHost')
b-) Select userNamePasswordValidationMode as custom
For clientCertificate tag(under serviceCredentials tag) properties, select certificateValidationMode as None and revocationMode as NoCheck
For serviceMetadata tag properties set HttpsGetEnabled as True
For serviceDebug tag properties set includeExceptionDetailInFaults as True
After these steps, resulting service model is:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="safe_behavior">
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="None" revocationMode="NoCheck" />
</clientCertificate>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="Rids.WcfHost.ServiceUserValidator, Rids.WcfHost" />
</serviceCredentials>
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<customBinding>
<binding name="custom_binding">
<security authenticationMode="UserNameOverTransport" />
<httpsTransport />
</binding>
</customBinding>
</bindings>
<services>
<service behaviorConfiguration="safe_behavior" name="Rids.Services.Services.SurveyService">
<endpoint address="" binding="customBinding"
bindingConfiguration="custom_binding" contract="Rids.Services.Services.ISurveyService" />
</service>
</services>
</system.serviceModel>

wcf with basic authentication through reverse proxy

I have a Web Service which uses basic authentication with ssl through a reverse proxy. It has already cost me quite some time to figure out how to get this working and I still fail to get it fully working.
if you type in the url in the browser https://domain.com/service.svc, it asks for credentials and if correct, you get the overview page of the service.
So that seems to be okay.
But when I try to add the Service to Visual Studio 2010, I get the following error:
Metadata contains a reference that cannot be resolved:
The document format is not recognized (the content type is 'text/html; charset=utf-8').
Metadata contains a reference that cannot be resolved: 'https://domain.com/service.svc'.
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Basic realm=NTLM'.
The remote server returned an error: (401) Unauthorized.
If the service is defined in the current solution, try building the solution and adding the service reference again.
Here is my web.config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="MyBinding">
<!--<httpsTransport authenticationScheme="Basic"/>-->
<security mode="TransportCredentialOnly">
<transport clientCredentialType="None" proxyCredentialType="Basic" realm="" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="WcfService1.PortalService" behaviorConfiguration="NorthwindBehavior">
<host>
<baseAddresses>
<add baseAddress="https://domain.com/" />
</baseAddresses>
</host>
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="MyBinding" contract="WcfService1.IPortalService">
<!--<identity>
<servicePrincipalName value=""/>
</identity>-->
</endpoint>
<!--<endpoint address="mex" binding="basicHttpBinding" bindingConfiguration="MyBinding" name="mex" contract="WcfService1.IPortalService"></endpoint>-->
</service>
</services>
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="https://domain.com/"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<!--<extensions>
<bindingElementExtensions>
<add name="httpsViaProxyTransport" type="WcfService1.HttpsViaProxyTransportElement, WcfService1"/>
</bindingElementExtensions>
</extensions>
<bindings>
<customBinding>
<binding name="UserNamePasswordSecured">
<textMessageEncoding />
<security authenticationMode="UserNameOverTransport" />
<httpsViaProxyTransport />
</binding>
</customBinding>
</bindings>-->
<behaviors>
<serviceBehaviors>
<behavior name="NorthwindBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
<serviceAuthorization principalPermissionMode="UseAspNetRoles"/>
<serviceCredentials> <userNameAuthentication userNamePasswordValidationMode="MembershipProvider"/></serviceCredentials>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="SampleEndpointBehavior">
<!--<wsdlExtensions location="http://domain.com/PortalService.svc" singleFile="true"/> -->
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
I tried numerous things like following this post: http://blog.hackedbrain.com/2006/09/26/how-to-ssl-passthrough-with-wcf-or-transportwithmessagecredential-over-plain-http/ but not very succesful.
I also tried to add site bindings to http because the wsdl is generating the server name instead of the domain name, so maybe there is something wrong at that end as well...
So hopefully someone can provide me with some pointers!
Note that the web.config file has some 'junk' in it because of trying with million different settings...

WCF with netTCPBinding

I have written wcf service
everything works fine when i deploy it on IIS7 with http binding.
I want to deploy the same on Windows Process Activation Services (WAS) using netcp binding.
when i try to create proxy for the service using svcutil
i am getting below error message:
Error: Cannot obtain Metadata from net.tcp://localhost/myservice/servi
ce.svc
If this is a Windows (R) Communication Foundation service to which you have acce
ss, please check that you have enabled metadata publishing at the specified addr
ess. For help enabling metadata publishing, please refer to the MSDN documentat
ion at http://go.microsoft.com/fwlink/?LinkId=65455.
WS-Metadata Exchange Error
URI: net.tcp://localhost/servicemodelsamples/service.svc
Metadata contains a reference that cannot be resolved: 'net.tcp://localhost/
servicemodelsamples/service.svc'.
here is web.config:
<system.serviceModel>
<services>
<service name="MyProj.Myservice"behaviorConfiguration="CalculatorServiceBehavior">
<!--This endpoint is exposed at the base address provided by host: net.tcp://localhost/servicemodelsamples/service.svc -->
<endpoint binding="netTcpBinding" bindingConfiguration="PortSharingBinding"contract="MyProj.ICalculator" />
<!--the mex endpoint is explosed at net.tcp://localhost/servicemodelsamples/service.svc/mex -->
<endpoint address="mex"binding="mexTcpBinding"contract="IMetadataExchange" />
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="PortSharingBinding" portSharingEnabled="true">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata />
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
Thanks,
on .net 4 check if "Net.Tcp Listener Adapter" service is using .net 4 version of SMSvcHost.exe (should be ...\v4.0.30319\SMSvcHost.exe)
If not repair installation of .net 4

WCF over IIS through load balancer reports wrong base address

I'm trying to launch a WCF service over SSL on IIS 6 through a load balancer. My initial problem was an obvious and pretty well discussed one - the address shown on the WSDL page pointed to https://SERVERNAME/WebServices/mydomainws.svc instead of www.mydomain.com. The answer to this problem is to add a host header value in IIS. I did that and it worked... sort of. I now get http://www.mydomain.com/WebServices/mydomainws.svc when viewing the wsdl in a browser. If I click on that link (the non-ssl link) I get a service definition that again references the server name.
The next oft recommended remedy is to use WCF Extras which provides an extension that allows you to specify a base address. But setting that config entry only updated the soap12:address. The EndPointReference address is still using the machine name.
To summarize: WSDL as viewed in web browser at https://www.mydomain.com/WebServices/mydomainws.svc: http://www.mydomain.com/WebServices/mydomainws.scv
Clicking the above link brings me to an actual wsdl file with the following service entry:
https://ServerName/WebServices/mydomainws.svc
My server config file has the following serviceModel entries:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<message clientCredentialType="None"/>
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="mydomain.ws.mydomainws" behaviorConfiguration="mydomainwsBehavior">
<!-- Service Endpoints -->
<endpoint address="" **behaviorConfiguration="CorrectEndPoint"** binding="wsHttpBinding" bindingConfiguration="TransportSecurity" contract="mydomain.ws.Imydomainws"/>
<endpoint address="mex" **behaviorConfiguration="CorrectEndPoint"** binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mydomainwsBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
**<behavior name="CorrectEndPoint">
<wsdlExtensions location="https://www.mydomain.com/WebServices/mydomainws.svc" singleFile="true"/>
</behavior>**
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<extensions>
<behaviorExtensions>
<add name="wsdlExtensions" type="WCFExtras.Wsdl.WsdlExtensionsConfig, WCFExtras, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
</system.serviceModel>
Can anyone point me in the right direction?
Thanks,
George
This should be handeled by new behavior useRequestHeadersForMetadataAddress. Try to add this to your service behavior:
<serviceBehaviors>
<behavior name="LoadBalancedBehavior">
<serviceMetadata httpGetEnabled="true" />
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<add scheme="http" port="80" />
<add scheme="https" port="443" />
</defaultPorts>
</useRequestHeadersForMetadataAddress>
<!-- Other service behaviors as necesary -->
</behavior>
</serviceBehaviors>
This behavior is availabel in WCF 4.0 and should be available as KB for WCF 3.x.