WCF with netTCPBinding - wcf

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

Related

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>

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

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>

Activation error in WCF web-service using basicHttpBinding, Windpws-Authentication & impersonation

I am trying to host a WCF web service in IIS using Windows Authentication. Due to restrictions, we have to use the basicHttpBinding & use impersonation (impersonate the caller's identity for accessing resources down the chain).
I have declaratively enabled impersonation on the operation contract of my WCF service:
[OperationBehavior(Impersonation = ImpersonationOption.Required)]
My web.config is:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="basic">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows">
</transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="NotesService">
<endpoint address="http://Client1.osp.local:15000/NotesService/NotesService.svc" bindingConfiguration="basic" binding="basicHttpBinding" contract="NotesService.ServiceContract.INotesService">
<identity>
<servicePrincipalName value="HTTP/Client1.osp.local:15000"/>
</identity>
</endpoint>
</service>
</services>
</system.serviceModel>
However, I am getting an activation error. What am I missing?
The error I am getting is:
The contract operation 'Process' requires Windows identity for automatic
impersonation. A Windows identity that represents the caller is not provided by
binding ('BasicHttpBinding','http://tempuri.org/') for contract
('NotesService','http://tempuri.org/'.
Assuming you are using WCF 4.0, then I think you are seeing an artefact of a WCF 4 feature called default endpoints.
In the service name you need to provide the fully qualified name of the service (including the namespace). Assuming NotesService is in a namespace then when you create the ServiceHost it doesn;t find a match in the config file. If you supply an HTTP base address in the ServiceHost constructor then it will wire up the basicHttpBinding with its default configuration (no authentication) which would produce the error you are seeing

Two endpoints in WCF 3.5 for SOAP and JSON

I dont know what I am doing wrong. I have a WCF (.NET 3.5) service (JsonSoap.svc) that has two endpoints for soap and json content type. Both the endpoints refer to the same service. I am using only one Json endpoint in the client. My aim is to have the service method GetPerson() to return Json or soap depending on the endpoints used to connect to the service (hopefully this is possible in WCF?). I can see wsdl and was able to successfully ad the service reference in to the client side.
I get the following error after I make a call to the GetPerson() -
"An error occurred while receiving the
HTTP response to
http://localhost:80/JsonSoap/json/GetPerson.
This could be due to the service
endpoint binding not using the HTTP
protocol. This could also be due to
an HTTP request context being aborted
by the server (possibly due to the
service shutting down). See server
logs for more details."
WCF service config
<!-- bindings -->
<bindings>
<basicHttpBinding>
<binding name ="soapBinding">
<security mode="None">
</security>
</binding>
</basicHttpBinding>
<webHttpBinding>
<binding name="webBinding">
</binding>
</webHttpBinding>
</bindings>
<!-- JSON behaviors -->
<endpointBehaviors>
<behavior name="jsonBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="defaultBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="TestService.IJsonSoap" behaviorConfiguration="defaultBehavior">
<host>
<baseAddresses>
<!-- note, choose an available port-->
<add baseAddress="http://localhost:80/JsonSoap" />
</baseAddresses>
</host>
<endpoint address="soap" binding="basicHttpBinding"
bindingConfiguration="soapBinding"
contract="TestService.IJsonSoap" />
<endpoint address="json" binding="webHttpBinding"
bindingConfiguration="webBinding"
behaviorConfiguration="jsonBehavior"
contract="TestService.IJsonSoap" />
</service>
WCF code:
[OperationContract]
[WebGet]
Person GetPerson(int ID);
WCF Client config:
<endpoint address="http://localhost:80/JsonSoap/json" binding="webHttpBinding"
bindingConfiguration="webBinding" behaviorConfiguration="jsonBehavior"
contract="MyService.IJsonSoap" />
Client code:
MyService.JsonSoapClient service = new JsonSoapClient();
MyService.Person person = service.GetPerson(10);
This will not work. WSDL servers only for SOAP services and it is the source for Add Service Reference in Visual Studio. You are using client code generated by Visual Studio but you are using it with Json endpoint which doesn't work.
Json endpoint represents REST service. To call WCF REST service in .NET you must either:
Build manully HTTP Request
Share service contract with a client and use ChannelFactory or WebChannelFactory to build a proxy
Use REST Starter KIT CTP2 and its HttpClient class (not recommended because development of REST Starter KIT ended).

WCF service problem with SSL

I have problem with call WCf service over SSL from console app. WCF service is on Windows Server 2003. It's simple math service. The WCF service and client are on the same computer. It's test, I call service on localhost.
web.confing
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="Service.CalculatorService" behaviorConfiguration="CalculatorServiceBehavior">
<endpoint address="https://machineName/https/calculatorservice.svc" name="myEndpoint" binding="basicHttpBinding"
bindingConfiguration="Binding1" contract="Service.ICalculator"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="Binding1">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="CalculatorServiceBehavior">
<serviceMetadata httpsGetEnabled="true"
httpsGetUrl="https://machineName/https/calculatorservice.svc" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.web>
<compilation debug="true"/></system.web></configuration>
If I call service from Visual Studio examaple : http://localhost:2039/CalculatorService.svc
I get error :
The protocol 'https' is not supported. I think it s ok.
But if I call service from browser I get error :
A registration already exists for URI 'https://machineName/https/CalculatorService.svc'.
What is bad? Can anybody help me, thank you.
Remove the "address" attribute from the endpoint element- when you're hosting in IIS, it automatically supplies this.
Visual Studio Development Server does not support https. You need to host your service in IIS
http://msdn.microsoft.com/en-us/library/vstudio/aa751792(v=vs.100).aspx