开发者

Selfhosted WCF service cant be tested via WCFTestClient

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

  1. Console Application that acts as host
  2. Service Contract
  3. Service implementation

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:

  • either define a base address and then use only relative addresses "on top" of that - for your regular and your MEX endpoint

OR:

  • define your addresses as full, complete addresses - not just for your regular endpoints, but in that case for the MEX endpoint as well.

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!


Are you running Windows 7?

Try running:

netsh http add urlacl url=http://+:2303/MyService user=DOMAIN\user

More info and here too


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 )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜