Updating Service References for specific endpoint - c#

My server used to communicate only with WCF client, and I added an additional access from the web using REST API. So currently the service's web.config contains two endpoints (one for each):
<services>
<service name="Server.Service">
<endpoint address="" bindingConfiguration="BasicHttpBinding_IServWCF" binding="basicHttpBinding" contract="Server.IWCF" />
<endpoint address="api" behaviorConfiguration="WebBehave" binding="webHttpBinding" contract="Server.IREST" />
</service>
</services>
The WCF client bindings:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IServWCF" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:1862/ServWCF.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServWCF"
contract="WCFServ.IWCF" name="BasicHttpBinding_IServWCF" />
</client>
Everything works OK, and I can access the server's methods from both ways - WCF and HTTP requests.
The problem - I tried to use the Update Service References feature, but it fails. I get the following error message:
The client and service bindings may be mismatched. the remote server returned an error 415
When I remove the new endpoint - behaviorConfiguration="WebBehave", the update service reference works fine. Can I somehow configure the Update References to use a specific end point?
Thanks

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

Service call failed in WCF through c#

I have a simple client and server file but service call fails, and I don't know why. Also, I am not able to find the contract name in the dll file.
Client :
<endpoint address="http://localhost/SelfHostedServiceConsole"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISampleService1"
contract="SelfHostedService.ISampleService" name="BasicHttpBinding_ISampleService1" />
</client>
</system.serviceModel>
</configuration>
I am calling using runclient.cmd:
set local
TestClient admin
pause
Every time I run this I just get
Using self hosted service
Service call failed
Client code:
<client>
<endpoint address="localhost/SelfHostedServiceConsole"; binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISampleService1&‌​quot; contract="SelfHostedService.ISampleService" name="BasicHttpBinding_ISampleService1" />
</client>

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.

WCF Endpoint. Multiple Clients

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

BasicHttpBinding and MessageVersion.None

How to configure XML web services client to use MessageVersion.Soap11WSAddressing10 for header namespaces. Currently it uses MessageVersion.None namespace, without me able to change it.
You need to do this using a custom WCF binding:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="Soap11Addr10">
<textMessageEncoding messageVersion="Soap11WSAddressing10" />
<httpTransport/>
</binding>
</customBinding>
</bindings>
and then reference that custom binding (by name) in your service endpoint:
<services>
<service name="YourAssembly.YourService">
<endpoint name="test"
address=""
binding="customBinding"
bindingConfiguration="Soap11Addr10"
contract="YourAssembly.IYourService" />
</service>
</services>
</system.serviceModel>
If you want to use this from a client, you also need to copy the custom binding configuration to the client's app.config or web.config and reference it there, of course (using Add Service Reference in Visual Studio will do this for you).

Categories

Resources