2011-06-13 136 views
2

我正在嘗試爲IIS 5.1上託管的WCF服務創建一個客戶端。我遇到了一個奇怪的問題:我可以通過瀏覽器訪問該服務就好,我看到「你已經創建了一個服務」頁面,但每當我嘗試運行SvcUtil工具(由同一頁面的建議)WCF服務客戶端問題

svcutil.exe http://my.host.name/SampleService/SampleService.svc?wsdl 

我得到以下錯誤:

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 /?" 

什麼導致這個問題呢?

編輯:它可能是IIS本身的問題?例如錯誤地設置權限?

編輯:這裏是我的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> 
+0

請發佈您的web.config(或app.config)文件。 – 2011-06-13 18:04:04

回答

1

我認爲這是相關的錯誤:

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate'.

是Web服務密碼保護或使用集成的Windows身份驗證?如果我沒有記錯,svcutil無法使用集成身份驗證登錄到Web服務。當您使用瀏覽器時,它工作得很好,因爲它處理Intranet環境的後臺驗證。

一種方法是手動下載並保存wsdl,然後指向svcutil以使用下載的wsdl文件生成類。您可能必須下載一些wsdl引用的文件並編輯引用。

+0

在IISManager中的 - > Properties-> DirectorySecurity下,我選中了匿名訪問,並且指定的帳戶可以訪問我的WINDOWS \ Temp,WINDOWS \ Microsoft.NET \ Framework \文件夾和我的項目源文件夾。什麼? – 2011-06-13 18:33:58