IIf I have multiple WCF services set up in a project like so:
ServiceA.svc
IServiceA.cs
ServiceB.svc
IServiceB.cs
And my web config has the following:
<services>
<service name="Services.ServiceA">
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration=""
contract="Services.IServiceA" />
<endpoint address="upload" binding="basicHttpBinding" bindingConfiguration="ImageUploadServiceBinding"
name="" bindingName="ImageUploadServiceBinding" contract="Services.IServiceB" />
</service>
</services>
Is that wrong? I ask because I have seen multiple ways of setting up WCF services when you have 'multiple' services and everyone seems to do it a different way. If I have multiple svc files in my project (multiple services), is it OK to group them into one "service" in the web.config and then separate them via endpoints like I have done above?
This will be hosted in IIS, btw.
I don't see why this would be a problem technically. WCF is built for this. You should keep in mind the deployment issues you could face.
Now, since it is one service, you can't just replace service A without replacing service B. This is okay if there are tightly coupled and share the exact same dependencies. If not, split them for maintainability.
Related
I have developed a WCF service which calls two clients to send files to each client.
I have done this by calling a single client and transferring the file is working fine. When I implement with more than one client it is getting a concurrency issue. I have looked at
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
But it's not working. When I debug, both service are executing in parallel and having problems with file resources.
Here is my client endpoint:
<client>
<endpoint address="xedt027/LeapClient/FileTransfer.svc"; binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFileTransfer" contract="ServiceReference1.IFileTransfer" name="BasicHttpBinding_IFileTransfer" />
<endpoint address="localhost:50152/FileTransfer.svc"; binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFileTransfer1" contract="ServiceReference2.IFileTransfer" name="BasicHttpBinding_IFileTransfer1" />
</client>
Is it possible for a WCF Service with two endpoints to provide a way, for the client, to generate his proxies from a specific endpoint ? I'm currently using the "Add Service Reference" feature from VS 2013 and it will obtain all classes defined by two contracts.
My two contracts define differents request/response. IServiceTCP provide admin-like methods and in IServiceHttp user-like methods.
Since I got a client who will only communicate in HTTP and he's not in the same network (making the endpoint in tcp useless), I would like to provide him a way to generate his proxies getting only classes needed from the http contract.
It seems I can provide an address to the endpoint that will be appended to the base address of the service. Since I'm hosted behind an IIS server, if I give the address "testhttp" to my endpoint, it would be resolved as "http://localhost/MyService/Service.svc/testhttp". I didn't found a way for a client to consume that address.
<service name="Namespace.Service" behaviorConfiguration="ServiceBehaviorA">
<endpoint binding="wsHttpBinding" bindingConfiguration="ServiceBindingHttp" contract="Namespace.IServiceHttp" />
<endpoint binding="netTcpBinding" bindingConfiguration="ServiceBindingTCP" contract="Namespace.IServiceTCP" />
</service>
I would like to avoid creating two services to achieve this purpose.
Thanks,
Not sure if this can be achieved without creating two services. If you're trying to create two endpoints, this is what you should try:
Give the two endpoints different service name:
<service name="Namespace.ServiceA" behaviorConfiguration="ServiceBehaviorA">
<endpoint binding="wsHttpBinding" bindingConfiguration="ServiceBindingHttp" contract="Namespace.IServiceHttp" />
</service>
<service name="Namespace.ServiceB" behaviorConfiguration="ServiceBehaviorA">
<endpoint binding="netTcpBinding" bindingConfiguration="ServiceBindingTCP" contract="Namespace.IServiceTCP" />
</service>
<serviceHostingEnvironment >
<serviceActivations>
<add relativeAddress="ServiceA.svc" service="Namespace.ServiceA" />
<add relativeAddress="ServiceB.svc" service="Namespace.ServiceB" />
</serviceActivations>/serviceHostingEnvironment>
Now the two endpoints should be accessible via
http://localhost/MyService/ServiceA.svc
http://localhost/MyService/ServiceB.svc
HTH.
I have a small WCF solution with 2 methods but am getting this error when I build it.
If I leave the message without dismissing it, I get
WCF Service Host cannot find any service metadata. This may cause the client application to run improperly. Please check if metadata is enabled.
I'm pretty sure my config is wrong, probably the defined endpoint does not match the namespace but I'm not sure what to set where.
The namespace of the Contracts class is JOB_1_0_Service.Contracts with 2 methods.
In the APP.Config of this project is the following:
<endpoint address="/Address1" binding="wsHttpBinding" contract="JOB_1_0_Service.Contracts.IService">
The contract methods are defined as:
[ServiceContract]
public interface IService
{
[OperationContract]
GetNearbyJobsResponse GetNearbyJobs(GetNearbyJobsRequest request);
[OperationContract]
GetChildJobsResponse GetChildJobs(GetChildJobsRequest request);
}
The namespace of the implementation class is JOB_1_0_Service.Implementation again with 2 methods:
GetNearbyJobsResponse IService.GetNearbyJobs(GetNearbyJobsRequest request)
{
...
}
and
GetChildJobsResponse IService.GetChildJobs(GetChildJobsRequest request)
{
...
}
What should I put in which config file - if indeed this is the problem?
[UPDATE]
Ok, so just to re-iterate:
I have 2 projects in 1 solution. 1 project contains the contracts and the other has the implementation code.
This also means there are 2 config files. So far I don't know which one needs modding in what way.
So, which is the one to modify, or do I need to modify both? I assume the implementation project is the one for the WCF config.
I'm now in the situation where, when I build it says I have no metadata exposed, and yet it also tries (and fails) to expose a contract as an endpoint!
[/UPDATE]
I was getting the same error becuase I had mistakenly commented out the [ServiceContract] attibute. Once I uncommented the [ServiceContract] attribute it all worked okay.
I hope this help others who face the same issue.
EDIT
Add the <serviceMetadata/> element to the service behavior for metadata
<configuration>
<system.serviceModel>
<services>
<service name="WCFTest.Service1" behaviorConfiguration="Simplebehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/WCFTest/"/>
</baseAddresses>
</host>
<endpoint
address=""
binding="basicHttpBinding"
contract="WCFTest.IService1"/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Simplebehavior">
<serviceMetadata/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Add below endpoint to exchange metadata
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
Aslo check this for detail : Random Error Message: WCF Service Host cannot find any service metadata
I had this error, and it turned out that I had the wrong project as the startup project: it was the first time I ever saw that error because of that, but oh well.
I just ran across this. In my case, I had three assemblies: one for the service, one for the client, and one class library shared by the first two. The shared assembly project had an app.config file automatically created by VS. Removing that file fixed the problem.
How do I get all the wcf 4.0 service addresses from each project in the Visual Studio solution when the services section endpoints in the web configs don’t specify an address or baseaddress? I intend to write the list of service addresses out to an aspx page. Any help would be appreciated.
Here's an example of one of the service sections in the web config.
<services>
<service name="ABC.Enterprise.Flight.FlightService">
<endpoint address="" binding="basicHttpBinding" name="ICRMManagement" contract="ABC.Enterprise.Flight.IFlightService"/>
<endpoint address="MexBasic" binding="mexHttpBinding" name="MexBasic" contract="IMetadataExchange" />
</service>
You could use WCF Discovery to find endpoints at runtime...
http://msdn.microsoft.com/en-us/library/dd456791.aspx
I am connecting a solution to a WCF SOAP based web service. The URL is in the format:
http://upload.pete.vls.com/api/hmlapi.svc
However when I add the reference the configuration comes up with the following:
<client>
<endpoint address="http://upload.pete.vls.com/api/HmlApi.svc/soap"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IHmlApi"
contract="ServiceReference1.IHmlApi" name="BasicHttpBinding_IHmlApi" />
</client>
Im confused as to why when I add the reference with /soap/ on the end it doesnt work. But when I dont add it, the 'add reference' feature finds the service and adds it with a /soap/ anyway.
The URL you are entering (without the soap part) includes information on what types of service transport are offered. VS is choosing soap from that, and saving the proper endpoint address in the config.
That end URL would not be correct for what is being asked for when you are prompted, though. Because it's expecting a URL with information on the service - not the actual endpoint that will eventually get used.
Because your endpoint on the server is probably configured like that
<services>
<service name="YourService">
<endpoint name="mySOAPEndpoint" address="soap" binding="someHttpBinding" contract="IYourService" />
</service>
</services>
Note that the address is "soap" which is the relative path after your service URI (i.e. after the .svc). If you write address="" then your .svc URI is the same as your endpoint address.