I am trying to test my self hosted wcf service using WCFTestClient. I get an error like so:
Error: Cannot obtain Metadata from http://localhost:2303/MyService If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: http://localhost:2303/MyService Metadata contains a reference that cannot be resolved: 'http://localhost:2303/MyService'. Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:2303/MyService . The client and service bindings may be mismatched. The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..HTTP GET Error URI: http://localhost:2303/MyService There was an error downloading 'http://localhost:2303/MyService'. The request failed with HTTP status 400: Bad Request.
My project structure is as follows
Here are my service implementation and Contract classes, which are in two separate projects.
namespace MyService
{
public class MyService : IMyService
{
public string GetGreeting(string name)
{
return "Hello " + name;
}
public string GetYelling(string name)
{
return "What the hell " + name + "!!";
}
}
}
namespace MyService
{
[ServiceContract]
public interface IMyService
{
[OperationContract]
string GetGreeting(string name);
[OperationContract]
string GetYelling(string name);
}
}
This is the console app
namespace MyWCFHost
{
class Program
{
static void Main(string[] args)
{
ServiceHost serviceHost = new ServiceHost(typeof(MyService.MyService), new Uri("http://localhost:2303"));
serviceHost.Open();
Console.WriteLine("MyService is running...");
Console.ReadKey();
serviceHost.Close();
}
}
}
This is the config file
<configuration>
<system.serviceModel>
<services>
<service name ="MyService.MyService" behaviorConfiguration="MyService.MyServiceBehavior">
<endpoint address="http://localhost:2303/MyService" binding="basicHttpBinding" contract="MyService.IMyService"/>
<endpoint address="mex" binding="mexHttpBinding" name="mexpoint" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyService.MyServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
What am I doing wrong?
Thanks for your time...
Edit
The service works when I try to run it via a winforms client so I know the service is working. Question is how do I get it ready for testing as well, using WcfTestClient.
I suspect you have a problem with your MEX endpoint. You're currently only specifying a relative address ("mex") - but there's no base address for HTTP defined in your service ......
I would suggest to:
OR:
So change your config to be something like:
<service name ="MyService.MyService" behaviorConfiguration="MyService.MyServiceBehavior">
<endpoint
address="http://localhost:2303/MyService"
binding="basicHttpBinding"
contract="MyService.IMyService"/>
<endpoint name="mexpoint"
address="http://localhost:2303/MyService/mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
and then I hope you should be able to get at your metadata and thus connect to your service!
Try to run your visual studio as administrator. Then you do not need to manually run the commands like (url=http://+:2303/MyService user=PCNAME\\mylogin )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.