2012-09-27 35 views
0

我創建了一個用作WCF客戶端的控制檯應用程序。在app.config由以下部分組成:WCF錯誤:ChannelFactory.Endpoint上的地址屬性爲空

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <customBinding> 
       <binding name="WebHttpBinding_IWebContentService"> 
        <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" 
         messageVersion="Soap12" writeEncoding="utf-8"> 
         <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
          maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
        </textMessageEncoding> 
       </binding> 
      </customBinding> 
     </bindings> 
     <client> 
      <endpoint address="http://localhost:1252/SomeService.svc" binding="customBinding" bindingConfiguration="WebHttpBinding_IWebContentService" 
       contract="WebContentClient.IWebContentService" name="WebHttpBinding_IWebContentService" /> 

     </client> 


    </system.serviceModel> 
</configuration> 

當我運行它,我得到以下錯誤:

The address property on ChannelFactory.Endpoint was null 

端點元素有一個地址屬性,但我不知道是什麼,我猜想分配該屬性。我正在本地主機上運行我的Web服務。

更新1:

我加入了地址,我已經更新了原來的代碼。但是我收到錯誤消息,說沒有端點監聽地址=「http:// localhost:1252/SomeService.svc」。如果我訪問wcf url,我可以看到web服務。

回答

2

您的自定義綁定配置不正確。你應該指定一個像httptransport這樣的傳輸元素。

這裏是一個有效的配置的例子:你爲什麼要使用一個自定義綁定

<customBinding> 
    <binding name="myCustomHttpBinding"> 
     <textMessageEncoding /> 
     <httpTransport/> 
    </binding >  
</customBinding > 

?取決於服務,有許多綁定(basicHttpBinding,webHttpBinding,...)更易於使用。

注:我認爲你的客戶端代碼也是不正確的,因爲這個例外。

0

您需要將其分配給Web服務的地址。如果它是本地主機上的WCF Web服務,它可能是以下形式:

http://localhost[:port]/<path>/SomeService.svc 
+0

感謝您的回覆!請參閱我已更新的原始帖子,在其中添加了地址,但仍然出現錯誤。 – azamsharp