Configuring MEX and service in separate sections in web.config - wcf

I have basic question - can we assume that both configurations does the same thing?
web.config one
<service behaviorConfiguration="endpointBehavior" name="mYwebSrv.mYDevice">
<endpoint address="" binding="basicHttpBinding" contract="mYwebSrv.ImYDevice"></endpoint>
</service>
<service behaviorConfiguration="endpointBehavior" name="mYwebSrv.mYDevice">
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
</service>
web.config two
<service behaviorConfiguration="endpointBehavior" name="mYwebSrv.mYDevice">
<endpoint address="" binding="basicHttpBinding" contract="mYwebSrv.ImYDevice"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
</service>

Not exactly.
Since you declared a new Service in your Web.config, it cannot have the same key for both services (endpointBehavior and name).
As you want to expose an endpoint to your service and an endpoint for the same service but for metadata (mex), it makes sense to put both under same service, that is as Microsoft recommends, see here: https://msdn.microsoft.com/en-us/library/ms734765.aspx
<service
name="Metadata.Example.SimpleService"
behaviorConfiguration="SimpleServiceBehavior">
<endpoint address=""
binding="wsHttpBinding"
contract="Metadata.Example.ISimpleService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
Hope it helps.

Related

This collection already contains an address with scheme Http

I want to have basic and Ws (over HTTP - Security is not a problem) and netTCP bindings at different urls.
<service name="WCFService.IHelloService" behaviorConfiguration="MyDefaultBehaviour">
<endpoint address="basicHttpAddress" binding="basicHttpBinding" contract="WCFService.IIHelloService"/>
<endpoint address="netTCPAddress" binding="netTcpBinding" contract="WCFService.IIHelloService"/>
<endpoint address="wsBindingAddress"
binding="wsHttpBinding" contract="WCFService.IIHelloService"
bindingConfiguration="wsBindingConfiguration"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8091/"/>
<add baseAddress="net.tcp://localhost:8095/"/>
<add baseAddress="http://localhost:8098/"/>
</baseAddresses>
</host>
Since I am having the multiple base address over the same protocol (http) I have also enabled multipleSiteBindingsEnabled .
But still I am having the same problem.
How to solve this?

NetNamedPipeBinding create an issue when service is restarted

We are using WCF service with NetNamedPipeBinding binding. It works without any problem.But some time when we replace service's bin in IIS or restart the service then client can not connect with service. During this error If we change the binding from NetNamedPipeBinding to BasicHttpBinding in client side then work perfectly.
Client does not receive the response from the service. So how we can overcome from this issue and just want to know what is the actual issue with NetNamedPipeBinding?
if there is an any better replacement of NetNamedPipeBinding.
Update:
Service side configuration
<services>
<service behaviorConfiguration="ServicesBehavior" name="WcfServices.Service1">
<endpoint address="soap" behaviorConfiguration="FlattenWsdlEndpointBehavior" binding="basicHttpBinding" contract="WcfServices.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="json" behaviorConfiguration="webHttpBehavior" binding="webHttpBinding" contract="WcfServices.IService1" />
<endpoint address="NamedPipe" binding="netNamedPipeBinding" contract="WcfServices.IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
Client side configuration
<client>
<endpoint address="http://someAddress/WcfServices/Service1.svc/soap" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1" contract="WcfServices.IService1" name="BasicHttpBinding_IService1" />
<endpoint address="net.pipe://localhost/WcfServices/Service1.svc/NamedPipe" binding="netNamedPipeBinding" bindingConfiguration="NetNamedPipeBinding_IService1" contract="WcfServices.IService1" name="NetNamedPipeBinding_IService1" />
</client>
Thanks in advance.
If someone can help me on this.

Can I use wsHttpBinding along with webHttpBinding in WCF service?

I have a custom username-password WCF service that needs to be called by Windows client (Winforms application) as well as by Web client (html/aspx page). I have two endpoints declarations in web.config but, to make it work, I have to comment one of them and so, only the client type, associated with that un-commented endpoint, can access the service. If I un-commment that, and comment the other one, other client can access it. I can't keep both of them and so I can't access it with both types of clients.
<service behaviorConfiguration="Behavior1" name="BeST.Service.Service">
<endpoint address="" binding="webHttpBinding" contract="BeST.Service.IService" behaviorConfiguration="EndpBehavior"></endpoint>
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1"
contract="BeST.Service.IService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/" />
</baseAddresses>
</host>
</service>
just as the code shows, I need to use both endpoints (above two endpoints) if I want to make this service work for both clients OR, if there's another way to have it done, please help!
The problem is that you are giving the same address to both endpoints. Try to give another relative address to one of your endpoints and it should work.
<service behaviorConfiguration="Behavior1" name="BeST.Service.Service">
<endpoint address="web" binding="webHttpBinding" contract="BeST.Service.IService" behaviorConfiguration="EndpBehavior"></endpoint>
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1"
contract="BeST.Service.IService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/" />
</baseAddresses>
</host>
</service>

What are the reasons that cause ServiceActivationException?

I have a service which is hosted in Azure environment. i am consuming that service using a console application. While doing so, i get exception:
"The requested service,
'http://xxxx-d.yyyy.be/Services/zzzzInService.svc' could not be
activated. See the server's diagnostic trace logs for more
information."
Can anyone help me to find what i am missing ?
The service is defined like this -
<service name="xxxx.AppServer.Host.Services.yyyyy.zzzzPlugInService"
behaviorConfiguration="MetadataBehavior" xdt:Locator="XPath(//service[#name='xxxx.AppServer.Host.Services.yyyy.zzzzPlugInService'])" xdt:Transform="Replace">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding" contract="xxxx.Shared.IntegrationServices.yyyy.IzzzzPlugInService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpsBinding" contract="xxxx.Shared.IntegrationServices.yyyy.IzzzzPlugInService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
When i Use the link http://xxxx-d.yyyy.be/Services/zzzzInService.svc in browser i get these messsage -
The binding at system.serviceModel/bindings/basicHttpBinding does not
have a configured binding named 'basicHttpBinding'. This is an invalid
value for bindingConfiguration.
source :
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBinding" contract="xxxx.Shared.IntegrationServices.zzzzz.IzzzzPlugInService">
The error says that you don't have a binding configuration for "basicHttpBinding" named "basicHttpBinding". Since you didn't post your complete config, and the error message says that, I'll assume that this is the case.
The config below (under <system.serviceModel>) has two binding definitions under <basicHttpBinding>, one for each binding configuration you have in your endpoint declarations. You should have something similar in your config as well.
<services>
<service name="xxxx.AppServer.Host.Services.yyyyy.zzzzPlugInService"
behaviorConfiguration="MetadataBehavior"
xdt:Locator="XPath(//service[#name='xxxx.AppServer.Host.Services.yyyy.zzzzPlugInService'])"
xdt:Transform="Replace">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="basicHttpBinding"
contract="xxxx.Shared.IntegrationServices.yyyy.IzzzzPlugInService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="basicHttpsBinding"
contract="xxxx.Shared.IntegrationServices.yyyy.IzzzzPlugInService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBinding" />
<binding name="basicHttpsBinding">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
One of the other reasons can be if you have a duplicate or overload methods in your svc.cs file

Is it possible to return different wsdls for different contracts on the same service?

I have a WCF service implementing two contracts on two different endpoints. I would like a client to be able to point at an endpoint (rather than the base address of the service) and get the wsdl just for the contract implemented on that endpoint (rather than a wsdl containing all contracts).
Is this possible? If so, how can it be achieved?
Instead of setting up the service like shown below (with a single SVC file if hosting in IIS)
<services>
<service name="YourOrg.YourService">
<endpoint address=""
binding="wsHttpBinding"
contract="YourOrg.IYourServiceThisContract" />
<endpoint address="That"
binding="wsHttpBinding"
contract="YourOrg.IYourServiceThatContract" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
Set each contract as a separate service class (with its own SVC file in the same IIS website)
<services>
<service name="YourOrg.ThisService">
<endpoint address=""
binding="wsHttpBinding"
contract="YourOrg.IYourServiceThisContract" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
<service name="YourOrg.ThatService">
<endpoint address=""
binding="wsHttpBinding"
contract="YourOrg.IYourServiceThatContract" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>