4

I am trying to use Svcutil to export metadata for proxy generation off a locally hosted service. I dont want to go into visual studio and click 'Add service reference' as this is a learning exercise on my part(!)

I am using svcutil as follows:

Svcutil /d:c:\temp /t:metadata http://localhost/IISCalculatorService/service.svc

This then generates two WSDL files, calculatorservice.wsdl and tempuri.org.wsdl. However I was expecting it to generate two .XSD files as well. Without these .XSD files I cant use svcutil to then generate the client code.

Am I missing something in my use of svcutil or is my understading fauly? Any help appreciated.

Here's the service's web.config

<?xml version="1.0"?>
<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0"/>
    </system.web>
  <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior>
          <serviceMetadata httpGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="false"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
        <services>
            <service name="CalculatorService.Calculator">
                <endpoint address="" binding="basicHttpBinding" contract="CalculatorService.Contracts.ICalculator" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
            </service>
        </services>
    </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
</configuration>
SkeetJon
  • 1,491
  • 1
  • 19
  • 40
  • 1
    You can generate the proxy using svcutil and then use the proxy in your project if you do not wish to do it via the Add service reference. If you want the xsd's related to the wsdl to validate something in it then you can simply download it from the specified url in wsdl and add it in your project – Rajesh Jan 09 '12 at 10:41

2 Answers2

4

Use disco.exe to generate XSD files. http://msdn.microsoft.com/en-us/library/cy2a3ybs%28v=vs.80%29.aspx

Open Visual Studio Command Prompt and write disco http://localhost/IISCalculatorService/service.svc

Per Kastman
  • 4,466
  • 24
  • 21
  • Thanks. This generates calculator.wsdl, services.disco, service.wsdl and results.discomap. (no .xsd files) The MSDN link then suggests using wsdl.exe to generate client code i.e .XSD isnt needed to feed svcutil? – SkeetJon Jan 09 '12 at 08:37
  • Is it possible the service is set up incorrectly in the web.config ? – SkeetJon Jan 09 '12 at 08:38
  • What is the goal you want to achieve? If you just want a C# proxy to call but don’t want to use the add service reference in VS you can just do svcutil http://localhost/IISCalculatorService/service.svc – Per Kastman Jan 09 '12 at 09:14
  • Hi, yes the goal is to create a c# proxy without using VS. – SkeetJon Jan 09 '12 at 09:42
3

If you are looking for service reference directly, you can try this

svcutil.exe http://localhost/IISCalculatorService/service.svc?wsdl

Hope this helps you.

Amar Palsapure
  • 9,590
  • 1
  • 27
  • 46
  • Thanks, tried this and get an error from svcutil stating "...the metadata documents did not contain any valid contracts or services...." – SkeetJon Jan 09 '12 at 08:41
  • Can you browse http://localhost/IISCalculatorService/service.svc and http://localhost/IISCalculatorService/service.svc?wsdl in IE? May be there is some issue with the hosting of your service. – Amar Palsapure Jan 09 '12 at 08:48
  • Yes can browse to them fine. Was thinking that the service wasn't letting svcutil/wsdl see the info it needs – SkeetJon Jan 09 '12 at 09:16
  • 1
    In your web.config, check this, your service should have one endpoint as , secondly, your service behavior should have – Amar Palsapure Jan 09 '12 at 09:19
  • The problem appears to be with IIS setup. If I host the same service via a Console app, svcutil generates the xsd and the wsdl files fine – SkeetJon Jan 09 '12 at 12:09
  • Try hosting your service on Web Server launched from Visual Studio. Secondly is your config same in both Console host and IIS host? – Amar Palsapure Jan 09 '12 at 12:17
  • The config was the same, and I've given up trying to configure IIS for the moment as it's not something I'm trying to learn how to do. Thanks for the help – SkeetJon Jan 10 '12 at 09:14