WCF Service client problem
I'm trying to create a client for a WCF service that I have hosted on IIS 5.1.I'm getting a strange problem: I can access the ser开发者_JAVA技巧vice through a browser just fine, I see the "You have created a service" page, but whenever I try running svcutil (as suggested by the same page)
svcutil.exe http://my.host.name/SampleService/SampleService.svc?wsdl
I get the following error:
Error: Cannot obtain Metadata from http://localhost.ms.com/SampleService/SampleS
ervice.svc?wsdl
If this is a Windows (R) Communication Foundation service to which you have acce
ss, please check that you have enabled metadata publishing at the specified addr
ess. For help enabling metadata publishing, please refer to the MSDN documentat
ion at http://go.microsoft.com/fwlink/?LinkId=65455.
WS-Metadata Exchange Error
URI: http://localhost.ms.com/SampleService/SampleService.svc?wsdl
Metadata contains a reference that cannot be resolved: 'http://localhost.ms.
com/SampleService/SampleService.svc?wsdl'.
The HTTP request is unauthorized with client authentication scheme 'Anonymou
s'. The authentication header received from the server was 'Negotiate'.
The remote server returned an error: (401) Unauthorized.
HTTP GET Error
URI: http://localhost.ms.com/SampleService/SampleService.svc?wsdl
There was an error downloading 'http://localhost.ms.com/SampleService/Sample
Service.svc?wsdl'.
The request failed with an empty response.
If you would like more help, type "svcutil /?"
What could be causing this problem?
EDIT: Could it be a problem with IIS itself? Incorrectly set permissions for example?
EDIT: Here's my web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="Basic">
<security mode="None"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="DummyService2.SampleService"
behaviorConfiguration="DummyService2.SampleServiceBehavior">
<!-- Service Endpoints -->
<endpoint address="" binding="basicHttpBinding" contract="DummyService2.ISampleService"
bindingConfiguration="Basic" />
<endpoint address="mex" binding="basicHttpBinding" contract="IMetadataExchange"
bindingConfiguration="Basic" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DummyService2.SampleServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
I think that this is the relevant error:
The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate'.
Is the web service password protected or using integrated Windows authentication? If I remember correctly, svcutil can't log on with integrated authentication to a web service. When you use a browser it works just fine, becuase it handles the authentication in the background for intranet environments.
One option is to download and save the wsdl manually and then point svcutil to use the downloaded wsdl file to generate the classes. You probably have to download some files that are referenced by the wsdl too and edit the references.
精彩评论