WCF Endpoint. Multiple Clients - c#

I have an IIS hosted WCF webservice. It started with two consumers.
1) A WinForm test harness in the same solution to test the WCF contracts in the IDE.
2) An Asp.Net Web App that is consuming the published version.
All was working out of the box so to speak.
Then along came the 3rd consumer, an Android app. To get this consuming correctly had to decorate the WCF contracts with JSON WebGets and Webinvokes and alter the WCF Web.config to suit.
Now the original two consumers no longer work. So I need to alter Web.config and / or App.configs to get a configuration where all three work.
Focusing on the IDE first. I have the following service model section for the WCF service Web.Config.
<system.serviceModel>
<client>
<endpoint binding="webHttpBinding" bindingConfiguration="JsonBinding"
contract="CouponParkingWCF.ICouponService" name="Json"
kind="" endpointConfiguration="">
<identity>
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="http://localhost:8707/CouponParking.svc"
binding="basicHttpBinding" contract="CouponParkingWCF.ICouponService"
name="BasicHttpBinding_ICouponService" />
</client>
<bindings>
<basicHttpBinding>
<binding name="basicHttp" />
</basicHttpBinding>
<webHttpBinding>
<binding name="JsonBinding" />
</webHttpBinding>
</bindings>
<services>
<service name="CouponParkingWCF.CouponService">
<endpoint behaviorConfiguration="JsonBehavior" binding="webHttpBinding"
bindingConfiguration="" name="jsonEndPoint"
contract="CouponParkingWCF.ICouponService" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="JsonBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="false" />
</system.serviceModel>
The WinForm Test harness App.config has:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttp" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8707/CouponParking.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttp"
contract="CouponParking.ICouponService"
name="BasicHttpBinding_ICouponService" />
</client>
</system.serviceModel>
I am not experienced at configuring endpoints and the above has been based on examples and guesswork.
When I run the Test Harness the wcf Client instantiates but a call on a contract fails with :
There was no endpoint listening at http://localhost:8707/CouponParking.svc
that could accept the message. This is often caused by an incorrect address
or SOAP action. See InnerException, if present, for more details."
The inner exception is :
{"The remote server returned an error: (404) Not Found."}
[System.Net.WebException]: {"The remote server returned an error: (404) Not Found."}
Data: {System.Collections.ListDictionaryInternal}
HelpLink: null
HResult: -2146233079
InnerException: null
Message: "The remote server returned an error: (404) Not Found."
Source: "System"
StackTrace: " at System.Net.HttpWebRequest.GetResponse()\r\n at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)"
TargetSite: {System.Net.WebResponse GetResponse()}
I would appreciate some guidance on what I have got wrong.
Thanks

At a glance, it appears that you've mixed up client endpoints with service endpoints in your service's config file. There's no reason for client endpoints to appear in the service's config file, unless that service is itself calling another service.
Your WinForm's config file is defining a client with basicHttpBinding, but you do not expose a service endpoint with BasicHttpBinding, which is most likely the reason for the error you're getting.
I would try deleting the client endpoints in your service's config file, and add them to the <services> section, like this:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttp" />
</basicHttpBinding>
<webHttpBinding>
<binding name="JsonBinding" />
</webHttpBinding>
</bindings>
<services>
<service name="CouponParkingWCF.CouponService">
<endpoint address="SOAP"
binding="basicHttpBinding"
contract="CouponParkingWCF.ICouponService"
name="BasicHttpBinding_ICouponService" />
<endpoint address="JSON"
binding="webHttpBinding" bindingConfiguration="JsonBinding"
contract="CouponParkingWCF.ICouponService" name="Json"
kind="" endpointConfiguration="">
<identity>
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
</service>
</services>
Remember the ABC's of WCF: A = Address, B = Binding and C = Contract - those three items define a service.
Since you added a client that needed a different binding then your test harness or your ASP.NET application, you need to expose a second endpoint with that binding.
EDITED
As #marc_s pointed out, you'll need two distinct relative addresses. I've updated the config file to reflect that.
I've not had an occasion to use multiple endpoints myself, but I believe you'd use them this way, with the base address being provided by the location of the *.svc file:
http://localhost:8707/CouponParking.svc/SOAP
http://localhost:8707/CouponParking.svc/JSON
With the first being for the BasicHttpBinding and the second being for the WebHttpBinding.

You basically just need two separate endpoints to provide both the basicHttpBinding (a SOAP binding) and the webHttpBinding for your Android client (a REST binding).
The "base" address of your service is defined by your IIS virtual directory and where the *.svc file lives (http://localhost:8707/CouponParking.svc) - so both services will be reachable at this "base" address plus any relative address defined
So you need to configure this something like this:
<services>
<service name="CouponParkingWCF.CouponService">
<!-- define the basicHttp (SOAP) endpoint at the base address -->
<endpoint name="SoapEndpoint"
address=""
binding="basicHttpBinding"
contract="CouponParkingWCF.ICouponService" />
<!-- define the REST endpoint at (base)+"/rest" -->
<endpoint name="RestEndpoint"
address="rest"
behaviorConfiguration="JsonBehavior"
binding="webHttpBinding"
contract="CouponParkingWCF.ICouponService" />
</service>
</services>
With this setup, you should be able to call your service using the basicHttpBinding (SOAP) at
http://yourServer:8707/CouponParking.svc
and you should be able to access the REST-based, JSON-enabled endpoint at
http://yourServer:8707/CouponParking.svc/rest
Both server-side endpoints will be handled by the same service code - it's just the endpoint (and the protocols that endpoints understands) that are different

Related

WCF service in client returns 404 over https

web.config settings on the server:
<service name="ExporterWebService">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="secureHttpBinding"
contract="IExporterWebService"/>
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
and client app.config is:
<client>
<endpoint
address="https://sample.coom/webservice/rwar.svc"
binding="wsHttpBinding" bindingConfiguration="basicHttpBinding"
contract="IRIBExporterWebService.IExporterWebService"
name="BasicHttpBinding_IExporterWebService"/>
</client>
<basicHttpBinding>
<binding name="BasicHttpBinding_IExporterWebService" maxReceivedMessageSize="2147483647">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
I am trying to test out WCF with SSL and seem to be missing something, I have done a ton of searching and can't seem to find what I'm missing with the config, I have a basic WCF service hosted in IIS, I also have a test client web application that is calling the WCF service.
Please help!!! :-)
You are supposed to type a wrong service address on the client-side when adding service reference.
The client would not generate a service endpoint created by Wshttpbinding when consuming a service created by Basichttpbiding.
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="secureHttpBinding"
contract="IExporterWebService"/>
<endpoint
address="https://sample.coom/webservice/rwar.svc"
binding="wsHttpBinding" bindingConfiguration="basicHttpBinding"
contract="IRIBExporterWebService.IExporterWebService"
name="BasicHttpBinding_IExporterWebService"/>
Besides, the server uses an empty relative endpoint address, while your client-side has a webservice prefix.
<client>
<endpoint
address="https://sample.coom/webservice/rwar.svc"
binding="wsHttpBinding" bindingConfiguration="basicHttpBinding"
contract="IRIBExporterWebService.IExporterWebService"
name="BasicHttpBinding_IExporterWebService"/>
Moreover, please trust the server certificate to establish a secure connection before making a call.
i have a mistake, we have tow webservice by tow address on server, & I forgot set config https webService new on server
thank you all friends

Problems with Hosting WCF service on IIS (Using WAS) for netTCP bindings?

I created a simple WCF service and hosted it in IIS by creating a new website. In Web.config file,I am providing bindings for http and net tcp.
I created a console client and adding service reference. It generates two binding in client config - for http and for tcp. When I try to invoke the service using tcp, I get this error -
An unhandled exception of type 'System.ServiceModel.EndpointNotFoundException' occurred in mscorlib.dll
Additional information: There was no endpoint listening at net.tcp://computername/Service.svc that could accept the message. This is often caused by an incorrect address or SOAP action.
when I run using Http endpoint , it works fine.
Note -
I am using Windows 10 OS, IIS 10.0 and WPAS\WAS (Windows Process Activation Service) are installed. I already enabled\checked HTTP Activation, TCP Activation in .Net framework in Windows features. And modified IIS server settings to include net tcp. Please check it in attached image.
My website Web.config file looks like
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NewBinding0" portSharingEnabled="true">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="My" name="WCFServiceOM.Service1"> <!-- the service name must match the configuration name for the service implementation. -->
<endpoint address="" binding="basicHttpBinding" contract="WCFServiceOM.IService1"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint binding="netTcpBinding" bindingConfiguration="NewBinding0" contract="WCFServiceOM.IService1" />
<endpoint address="mexOM" binding="mexTcpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8087/Service1" />
<add baseAddress="http://localhost:7777/Service1"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehanior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="My">
<!-- 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>
And my client App.Config look like
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
<netTcpBinding>
<binding name="NetTcpBinding_IService1">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="http://computername:7777/Service.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
<endpoint address="net.tcp://computername/Service.svc" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IService1" contract="ServiceReference1.IService1"
name="NetTcpBinding_IService1" />
</client>
</system.serviceModel>

adding a service reference to net.msmq wcf service

I'm trying to add a service reference to my wcf app in visual studio.
I can do it for various bindings such as net.pipe and basichttp...
but to net.msmq binding, I get error
Here is the relevant part of my web.config:
<system.serviceModel>
<bindings>
<netMsmqBinding>
<binding name="netMsmqBinding" exactlyOnce="false">
<security mode="None"></security>
</binding>
</netMsmqBinding>
<basicHttpBinding>
<binding name="basicHttp" />
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="WCF_ServiceSample.WCF_ServiceBehavior" />
</endpointBehaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceMetadata />
<serviceDebug />
<serviceDiscovery />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<services>
<service behaviorConfiguration="serviceBehavior" name="WCF_ServiceSample.WCF_Service">
<host>
<baseAddresses>
<add baseAddress="http://localhost:4000/Services/" />
<add baseAddress="net.msmq://localhost/Services/" />
</baseAddresses>
</host>
<endpoint address="mex" behaviorConfiguration="WCF_ServiceSample.WCF_ServiceBehavior"
binding="mexHttpBinding" bindingConfiguration="" name="mex_http"
contract="IMetadataExchange" />
<endpoint address="AdventureWorksServiceHttp" binding="basicHttpBinding" bindingConfiguration=""
name="basicHttpEndpt" contract="WCF_ServiceSample.WCF_Service" />
<endpoint address="AdventureWorksServiceNetMsmq"
binding="netMsmqBinding" bindingConfiguration="netMsmqBinding"
contract="WCF_ServiceSample.WCF_Service" />
</service>
</services>
</system.serviceModel>
Here is the error I get when I run my service via the wcf client:
Error: Cannot obtain Metadata from
http://localhost:9011/WCF_Service.svc 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
http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange
Error URI: http://localhost:9011/WCF_Service.svc Metadata contains a
reference that cannot be resolved:
'http://localhost:9011/WCF_Service.svc'. The server did not provide a
meaningful reply; this might be caused by a contract mismatch, a
premature session shutdown or an internal server error.HTTP GET Error
URI: http://localhost:9011/WCF_Service.svc There was an error
downloading 'http://localhost:9011/WCF_Service.svc'. The request
failed with the error message:-- Server Error in '/' Application.
Could not find a base address that matches scheme net.msmq for the
endpoint with binding NetMsmqBinding. Registered base address schemes
are [http]. Description: An unhandled exception occurred during the
execution of the current web request. Please review the stack trace
for more information about the error and where it originated in the
code.
here is the error I get when I go to add service reference ->
net.msmq://localhost/WCF_Service.svc
then I press "Go"
The URI prefix is not recognized. The MetadataExchangeClient instance
could not be initialized because no Binding is available for scheme
'net.msmq'. You can supply a Binding in the constructor, or specify a
configurationName. Parameter name: scheme If the service is defined in
the current solution, try building the solution and adding the service
reference again.
add mex bindings as that will allow you to add proxy reference, then you can use the net.msmq bindings to do the operation.
What is "mexHttpBinding"?
https://msdn.microsoft.com/en-us/library/aa967390(v=vs.110).aspx

Enabling http and https on the same service

I am writing a WCF service which contains a singe contract. I would like web clients to call the service endpoint using either http or https.
My web.config is as follows:
(Some parts have been removed for brevity)
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IDataService" />
<binding name="BasicHttpsBinding_IDataService" >
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="DataServiceMetadataBehavior" name="DummyService.DataService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDataService"
contract="DummyService.IDataService"/>
<endpoint address=""
binding="basicHttpBinding" bindingConfiguration="BasicHttpsBinding_IDataService"
contract="DummyService.IDataService" name="BasicHttpsBinding_IDataService"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DataServiceMetadataBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add scheme="http" binding="basicHttpBinding" />
<add scheme="https" binding="basicHttpBinding" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
When I try to test the service using the VisualStudio test client, it gives the following error:
Could not find a base address that matches scheme https for the
endpoint with binding BasicHttpBinding. Registered base address
schemes are [http].
Everything works fine with only a single endpoint.
An endpoint consists of address, binding and contract.
http://YourBaseAddress/YourApp/YourService.svc and httpS://YourBaseAddress/YourApp/YourService.svc are different address with different schema name or protocol as well as different ports: 80 and 443 by default, so you can have both endpoints for the service, with the same basicHttpBinding, provided that the https one has a bindingConfiguration for SSL transportation as you had done. The error message is quite informative, so you need to go to IIS (or IIS Express) to make sure there's a http listener, say https binding defined after checking the "Edit Bindings" function of the Website. After you had done so, you should be able to get WSDL through httpS://YourBaseAddress/YourApp/YourService.svc?wsdl in a Web browser.
In fact, many Web services/applications like those from Microsoft and Google support both http and https through the same host name and path.

Adding a Service Reference to a NetTcp service using Add Service Reference... dialog [duplicate]

This question already has answers here:
WCF NetTcpBinding with mex
(3 answers)
Closed 8 years ago.
I defined a service. It´s service model node in the App.config is:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBindingConfiguration">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="Products.ProductsServiceImpl">
<endpoint address="net.tcp://localhost:8080/Whatever" binding="netTcpBinding"
bindingConfiguration="NetTcpBindingConfiguration" name="NetTcpBinding_IProductsService"
contract="Products.IProductsService" />
</service>
</services>
</system.serviceModel>
But when trying to add the service reference to a client app, I run the service, then I try to add the service reference using the Add Service Reference... dialog, but I can´t locate the service.
If I add an endpoint that uses basicHttpBinding, then the service is localizable via the Add Service Reference dialog.
I tried adding an endpoint that uses mexTcpBinding, but I got an error when trying to start the service, I got an error saying that the contract IMetadataExchange could not be found in the list of contracts implemented by my service.
What could I be missing?
Update:
This service is being opened using the ServiceHost class (an extract of the WPF App that's in charge of starting the service:):
var productsServiceHost = new ServiceHost(typeof(ProductsServiceImpl));
productsServiceHost.Open();
stop.IsEnabled = true;
start.IsEnabled = false;
status.Text = "Service Running";
And I used a WCF Library to create the service (where the service and contract are defined))
Got it!
I used this blog: http://debugmode.net/2010/06/16/nettcpwcfserviceinwindowservice/
The "mex" endpoint should use "mexTcpBinding"
Have to define the host base address, and leave the main endpoint address blank
httpGetEnabled was set to false
Here's the complete service model node (App.config)
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBindingConfiguration">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="Products.ProductsServiceImpl" behaviorConfiguration="metadataSupport">
<endpoint address="" binding="netTcpBinding"
bindingConfiguration="NetTcpBindingConfiguration" name="NetTcpBinding_IProductsService"
contract="Products.IProductsService" />
<endpoint name="MetaDataTcpEndpoint"
address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8080/Whatever" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metadataSupport">
<serviceMetadata httpGetEnabled="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
When placing the address in the Add Service Reference... dialog, it should be as:
net.tcp://localhost:8080/Whatever/mex
Although if you have started your service, when pressing Go in the Add Service Reference..., it appends the mex text for you if you haven't
Security mode="none" is usefull to access the service from other machines of the network
Happy coding.

Categories

Resources