I develop a WCF service (3.5) in VS 2010. Generally I am able to test it via the WCF Test Client and call the service from any browser. I'm on my Windows 7 development machine, so everything is default. The address is like http://localhost:54538/MyService.svc
However, when I try to call the service from a third party client (which in the end is my target), the client gets no response at all. The response is just empty. I also tried to call the service by PHP curl from a local Apache webserver - also an empty response.
So I think there might be a problem with the configuration. The services part is:
<services>
<service behaviorConfiguration="MyNamespace.Service1Behavior" name="MyNamespace.MyService">
<endpoint address="" binding="wsHttpBinding" contract="MyNamespace.IMyService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
Do I have to add an endpoint or change anything else?
So the solution I found (based on #marc_s' comment) is adding another endpoint as webHttpBinding:
<endpoint address="rest" binding="webHttpBinding" contract="MyNamespace.IMyCometService" bindingConfiguration="UnsecuredWeb">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
Then calling the service from the third party software via http://localhost:54538/MyService.svc/rest
Related
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.
suppose my wcf has many end point with different binding.so when user / client add service ref from VS IDE at then multiple endpoint related data expose & added in client config file at client side.
Can we design service in such a way as a result only one endpoint related address will be revealed at client side?
Suppose I have one service with HTTP & TCP related endpoint and I want when external customer will add our service from their VS IDE then they will see our HTTP endpoint address not TCP. So guide me how could I do this? How to design service end config file for my requirement?
here i am attaching a small sample code for multiple endpoint related in config file.
<services>
<service behaviorConfiguration="MulContractService" name="MyWCFLibrary.MultipleContract">
<clear />
<endpoint binding="basicHttpBinding" bindingConfiguration="MulContractBasicBinding"
name="MulContractBasicEndPoint" contract="MyWCFLibrary.IMultipleContract"
listenUriMode="Explicit">
<identity>
<dns value="localhost" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="test1" binding="wsHttpBinding" bindingConfiguration="MulContractWsHttpBinding"
name="MulContractWsHttp" contract="MyWCFLibrary.IByeWorld"
listenUriMode="Explicit">
<identity>
<dns value="localhost" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="test1" binding="wsHttpBinding" bindingConfiguration="MulContractWsHttpBinding"
name="MulContractWsHttp" contract="MyWCFLibrary.IHelloWorld"
listenUriMode="Explicit">
<identity>
<dns value="localhost" />
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
<endpoint address="net.tcp://localhost:8733/Design_Time_Addresses/MyWCFLibrary/MultipleContract/"
binding="netTcpBinding" bindingConfiguration="MulContractTCPBinding"
name="MulContractTCPEndPoint" contract="MyWCFLibrary.IMultipleContract" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/MyWCFLibrary/MultipleContract/" />
</baseAddresses>
</host>
</service>
</services>
EDIT
here i am giving my new full code and just guide me does it work?
namespace CustomService
{
[ServiceContract]
public interface IEmp
{
[OperationContract]
string GetEmp();
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class BusinessLayer : IEmp
{
public BusinessLayer()
{
}
public string GetEmp()
{
return "Casino";
}
}
}
Config code at service end
<services>
<service name="CustomService.BusinessLayer">
<endpoint address="CustomerFactory" binding="basicHttpBinding"
bindingConfiguration="HTTPBindingConfig" name="CustomerFactoryHTTP"
contract="CustomService.IEmp" listenUriMode="Explicit" />
</service>
<service name="CustomService.BusinessLayer">
<endpoint binding="basicHttpBinding" bindingConfiguration="HTTPBindingConfig"
name="CustomerMasterHTTP2" bindingName="CustomerMaster" contract="CustomService.IEmp" />
</service>
</services>
just tell me the above config will work?
in the above config i define two service tag with same name because my service full name with namespace is CustomService.BusinessLayer
is it ok or do i need to give unique name for each service tag?
my intention is i will have same service but with multiple service tag and when customer will add my service ref at their end then they will not be able to see all the endpoint.
my intention is not expose all endpoint & address to every client.
so guide me what i have done does it work or not....if not then rectify my config entry and tell me how could i restrict my endpoint not to expose each binding & address before all client. thanks
Maybe not what you are looking for but you could easily add another service to your project and give it the endpoints you want your client to see. Then the existing service could be just for TCP or for both types. Under the covers of course both services would run the same code.
Adding a service is just like adding any other file, right click, add New Item, WCF service. Then you can use the WCF configuration Editor to configure it if you dont want to do it by hand.
For what it is worth here is a config with two services. You can see that the first service has two endpoints, an Http and a TCP while the second service exposes just the http endpoint. Your two services would then each implement IService and would delegate to a common class or library.
<services>
<service name="Mynamespace.Service1">
<endpoint binding="basicHttpBinding"
bindingConfiguration="HTTPBindingConfig" name="MyserviceHTTP"
contract="Mynamespace.IService" listenUriMode="Explicit">
</endpoint>
<endpoint binding="netTcpBinding"
bindingConfiguration="TCPSecured" name="MyserviceHTTP"
contract="Mynamespace.IService" />
</service>
<service name="Mynamespace.Service2">
<endpoint binding="basicHttpBinding"
bindingConfiguration="HTTPBindingConfig" name="MyserviceHTTP"
contract="Mynamespace.IService" listenUriMode="Explicit">
</endpoint>
</service>
</services>
I have 3 service contract interfaces in my WCF library like this:
public interface ServiceContract1{}
public interface ServiceContract2{}
public interface ServiceContract3 : ServiceContract1, ServiceContract2 {}
Also I have a service which implements ServiceContract3. I can have different endpoints by setting different contracts for each like this:
<endpoint address="net.tcp://localhost:5556/ServiceContract1"
binding="netTcpBinding" name="netTcpBinding1"
contract="WcfServiceLibrary.IServiceContract1">
<endpoint address="net.tcp://localhost:5556/ServiceContract2"
binding="netTcpBinding" name="netTcpBinding2"
contract="WcfServiceLibrary.IServiceContract2">
These endpoints seem to work very well but there is only one mexHttpBinding endpoint automatically generated. Thus, although a client needs to use one of the endpoints, it will have whole classes after adding Service Reference.
Can i have different mexHttpBinding endpoints for different contracts? Is there any approach can i follow? Thanks for your help.
Edit #1: ServiceModel configuration
<system.serviceModel>
<services>
<service name="WcfServiceLibrary.Service">
<endpoint address="net.tcp://localhost:5556/Service1"
binding="netTcpBinding" name="netTcpBinding"
contract="WcfServiceLibrary.IServiceContract1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="net.tcp://localhost:5556/Service2"
binding="netTcpBinding" name="netTcpBinding"
contract="WcfServiceLibrary.IServiceContract2">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding"
name="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:5555/ConsoleHost" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
I have only one service hosted in my console application:
ServiceHost host = new ServiceHost(typeof(WcfServiceLibrary.Service));
host.Faulted += new EventHandler(Host_Faulted);
// Start listening for messages
host.Open();
First off I'll apologise as this is probably a duplicate but everything I read seems to be either incomplete or confusing as I'm very new to WCF.
I basically am looking to deploy a WCF service in IIS with 2 endpoints accessible and have been going around in circles all day :(
I have a service library WCF dll with the following structure
App.config
TestSvc1.cs
ITestSvc1.cs
TestSvc2.cs
ITestSvc2.cs
This works fine in the VS WCF test client and now im deploying to IIS so I created a WCF Service Application and referenced the dll. This project has the following structure
Service1.svc
Web.config
Service1.svc contains this
<%# ServiceHost Language="C#" Debug="true"
Service="WCFServices.TestServices.ITestSvc1" CodeBehind="Service1.svc.cs" %>
and my web.config has the following
<services>
<service name="WCFServices.TestServices.TestSvc2">
<endpoint
address=""
binding="wsHttpBinding" bindingConfiguration="LargeSizeMessages"
contract="WCFServices.TestServices.ITestSvc2">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/wcf2/TestServices/TestSvc2/" />
</baseAddresses>
</host>
</service>
<service name="WCFServices.TestServices.TestSvc1">
<endpoint
address=""
binding="wsHttpBinding" bindingConfiguration="LargeSizeMessages"
contract="WCFServices.TestServices.ITestSvc1"
listenUri="http://localhost:8080/wcf2/service1.svc">
<identity>
<dns value="" />
</identity>
</endpoint>
<endpoint
address=""
binding="wsHttpBinding" bindingConfiguration="LargeSizeMessages"
contract="WCFServices.TestServices.ITestSvc2"
listenUri="http://localhost:8080/wcf2/service1.svc">
<identity>
<dns value="" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/wcf2/TestServices/TestSvc1/" />
</baseAddresses>
</host>
</service>
</services>
Any help would be greatly appreciated. As you can see I've tried to add an additional endpoint in the web.config but this doesn't work, I get an error saying that TestSvc2 calls can't be found in TestSvc1 which I guess relates to the entry in Service1.svc
I also read about creating a class that inherits these interfaces but I am not sure exactly how to implement it based on what I have above. Do I need to modify the Service1.svc?
public interface MultipleSvc : ITestSvc1, ITestSvc2
{
// What exactly do I put here? I have no idea, do I leave it blank? This didn't work for me
}
Any help would be greatly appreciated guys thanks :)
Golden rule: one .svc = one service (or more specifically: one service implementation class)
So if you do have two separate, distinct services (in classes WCFServices.TestServices.TestSvc1 and WCFServices.TestServices.TestSvc2), then you need two .svc files (one each, for each service)
What you could do is have one service implementation class that implements both service contracts:
public class MultipleServices : ITestSvc1, ITestSvc2
{
// implement the service logic here, for both contracts
}
In that case, one svc file will be enough (the .svc file is per implementation class and can host multiple service contracts). But then you'd need to change your config, too - since you really only have one service class (therefore: one <service> tag) and multiple contracts hosted inside it:
<services>
<service name="WCFServices.TestServices.MultipleServices">
<endpoint
address="Service1"
binding="wsHttpBinding" bindingConfiguration="LargeSizeMessages"
contract="WCFServices.TestServices.ITestSvc1">
<identity>
<dns value="" />
</identity>
</endpoint>
<endpoint
address="Service2"
binding="wsHttpBinding" bindingConfiguration="LargeSizeMessages"
contract="WCFServices.TestServices.ITestSvc2">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
Also: since you seem to be hosting your WCF service in IIS, there's no point in defining any <baseAddress> values - the "base" address of your service is the location (URI) where the *.svc file lives.
You do'nt need two svc file. Choose ServiceReference1.Service1Client or ServiceReference1.Service2Client.
My WCF service has two endpoints(Normal and REST, one for Silverlight client and other for HTML5 client) and my Silverlight client application works perfectly without any issues. When I open my service in the IE, I am getting HTTP 400 bad request. It looks like REST part of my service has some issue. I have given both end points below. Appreciate any help!
Normal end point
<endpoint address="" binding="basicHttpBinding" contract="Test.Service1"
bindingConfiguration="BasicHttpBinding_Config"
behaviorConfiguration="MessageInspectorEndpointBehavior">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
WCF end point
<endpoint address="rest" binding="webHttpBinding" contract="Test.Service1"
behaviorConfiguration="web">
</endpoint>
The request should be made to .../WCF/Test/Service1.svc/rest, since this is the address for the REST endpoint you added in config.