2014-10-17 149 views
1

我是WCF服務的新手,但從來沒有得到我的頭腦和綁定。我現在使用的服務,如果在WCFTestClient中測試,但工作正常,但不會公開WSDL以供其他應用程序使用。我不確定它是如何完成的。下面是代碼:WCF服務未發佈wsdl

<system.serviceModel> 
<behaviors> 
    <serviceBehaviors> 
    <behavior> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="false"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

<bindings> 
    <basicHttpBinding> 
    <binding name="DefaultBindingConfig"> 
     <!--<security mode="none"> 
     <transport clientCredentialType="none" /> 
     </security>--> 

    </binding> 
    </basicHttpBinding> 
</bindings> 

<services> 
    <service name="Service.SecurityService"> 
    <endpoint address="" 
       name="SecurityServiceEndpoint" 
       binding="basicHttpBinding" 
       bindingConfiguration="DefaultBindingConfig" 
       contract="Service.Contracts.ISecurityService" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    </service> 
</services> 
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 

[ServiceContract] 
    public interface ISecurityService 
    { 
    [OperationContract] 
    ApplicationSecurity GetFunctionsAllowedForUser(string userName, string applicationName);  
} 

我怎樣才能讓這個本服務公開的WSDL?我對此很新。

回答

0

以下行應該公開元數據的WSDL:

<serviceMetadata httpGetEnabled="true"/> 

在瀏覽器中,轉到無論svc的Web地址,並添加?wsdl到它的結束。

http://localhost:<Port>/<OptionalFolders/>MyService.svc?wsdl 

如果一切工作正常,你應該有一堆XML。

+0

是的,我試過,但是當我去localhost:8000/Service.svc?wsdl,它給了我一個400錯誤的請求錯誤。我不確定是什麼原因導致出錯:/ – 2014-10-17 16:04:24

+0

那麼,您的港口可能與我的港口不同。轉到項目屬性 - > Web。查看是否有指定的端口或特定的文件夾地址。或者更好的辦法是,使用WCFTestClient中的地址,並在最後加上'?wsdl'。 – Cameron 2014-10-17 16:06:59

+0

是的,我已經把服務的端口和我在這裏的服務放在一起。但是,它仍然會顯示400錯誤請求錯誤。我試過去/ mex或?wsdl,但都返回相同的:/ 它可能是與我運行它的服務器有關嗎? – 2014-10-17 16:16:28