0

I am trying to take a very simple (essentially empty/function-less) service I have and generate a proxy with svcutil.exe. Here's my server:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.ServiceModel;

class Server2
{
    static void Main(string[] args)
    {
        Console.WriteLine("Server");

        Uri baseAddress = new Uri("http://localhost:1234");
        var host = new ServiceHost(typeof(TheContractService), baseAddress);
        //host.AddServiceEndpoint(typeof(TheContractService), new WSHttpBinding(), "ContractService");
        host.Open();

        Console.ReadLine();
    }
}

[ServiceContract]
class TheContractService
{
    [OperationContract]
    void Expose()
    {
        Console.WriteLine("Exposed");
    }
}

[DataContract]
class TheContract
{
    [DataMember]
    public string PublicProperty { get; set; }
    [DataMember]
    public string PublicField;
    [DataMember]
    private string PrivateProperty { get; set; }
    [DataMember]
    private string PrivateField;
    [DataMember (Name = "BetterName")]
    private string fudshjguhf;
}

Now I just need to set up my .config file to allow MEX -- here is my server config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>    
    <services>
      <service name="ContractService"
               behaviorConfiguration="MexServiceBehavior">

        <endpoint address="ContractService"
                  binding="basicHttpBinding"
                  contract="TheContractService"
        />

        <endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange"
        />
      </service>
    </services>

    <behaviors>
      <serviceBehaviors>
        <behavior name="MexServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>                  
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

What am I doing wrong here? When I try to run this command: svcutil /t:code http://localhost:1234/mex /out ContractService.cs /config: ContractService.config

I get either 400 or 405 errors and the client proxy is not generated successfully. Can anyone see any issues with what I currently have? Thanks!

Chris V.
  • 1,123
  • 5
  • 22
  • 50
  • Just curious, have you added that URL to the access list using netsh? The command would be something like "netsh add urlacl url=http://+:1234/ user=DOMAIN\user" with your Windows domain and username – Trevor Elliott Aug 28 '12 at 21:15

1 Answers1

0

Your class name is TheContractService, but in your config the name attribute of the <service> element is ContractService. Make sure that the value of that attribute is the fully-qualified name (namespace, if any, plus the class name), otherwise the configuration won't be picked up.

carlosfigueira
  • 85,035
  • 14
  • 131
  • 171