问题
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]
回答1:
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.
回答2:
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
回答3:
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.
回答4:
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.
来源:https://stackoverflow.com/questions/13626175/the-target-assembly-contains-no-service-types-you-may-need-to-adjust-the-code-a