2010-06-30 71 views
0

我在這兩個程序上都有相同的應用程序配置
A - 服務本身,當我運行它時,wcf測試客戶端啓動。
乙 - 使用自宿主程序 - new ServiceHost(typeof(MyService)))same app.config:wcftestclient work,selfHosting doesnot

那就是:

<services> 
    <service name="MyNameSpace.MyService" 
      behaviorConfiguration="MyService.Service1Behavior"> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost:5999/MyService"/> 
     </baseAddresses> 
    </host> 
    <endpoint 
      binding="basicHttpBinding" 
      contract="StorageServiceInterface.IService1" 
      bindingConfiguration="MyBasicHttpBinding" 
      name="basicEndPoint"> 

     <identity> 
     <dns value="localhost"/> 
     </identity> 
    </endpoint> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
    </service> 
</services> 


<bindings> 
    <basicHttpBinding> 
    <binding name="MyBasicHttpBinding"> 
     <security mode="None"> 
     <transport clientCredentialType="None" /> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 


<behaviors> 
    <serviceBehaviors> 
    <behavior name="HeziService.Service1Behavior">   
     <serviceMetadata httpGetEnabled="true"/>   
     <serviceDebug includeExceptionDetailInFaults="true"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

客戶端使用ClientBase<StorageServiceInterface.IService1>
客戶端的app.config:

<system.serviceModel> 
    <client> 
     <endpoint address="http://myIp/MyService" 
        binding="basicHttpBinding" 
        contract="StorageServiceInterface.IService1">     
     </endpoint> 
    </client> 
</system.serviceModel> 

當我運行selfhost程序和做host.open()
它並打開它,但是當我嘗試調用一個方法,它告訴我說:

"No connection could be made because the target machine actively refused it 10.0.0.1:5999"

ofcourse當服務運行從WCF測試客戶端,每件事情都起作用。 它怎麼可能?

在此先感謝

+1

你能告訴我們你的自託管應用程序的代碼? – 2010-06-30 15:15:34

回答

0

一些奇怪的事情:

關於marc_s這讓我寫我的selfhost PROG代碼..

我使用:

private void m_startServiceToolStripMenuItem_Click(object sender, EventArgs e) 
{ 
    using (Host = new ServiceHost(typeof(MyNameSpace.MyService))) 
    { 
     Host.Open(); 
    } 
} 

之前,我已經把它添加到我的問題試圖改變它沒有using部分:

private void m_startServiceToolStripMenuItem_Click(object sender, EventArgs e) 
{ 
    Host = new ServiceHost(typeof(yNameSpace.MyService)); 
    Host.Open(); 
} 

,現在它的工作!

但是,不知何故它的工作之前...
謝謝大家反正:-)

+1

嗯,是的 - 使用()....將摧毀在關閉的主機}並處置它。所以這絕對不會奏效.... – 2010-06-30 16:08:48

0

只是猜測 - 如何添加一個地址到你的服務器端的端點:

<endpoint address="" .... > 

是,基址基本定義了整個地址 - 但你還是應該添加地址到您的服務端點 - 即使它是空的。

+0

did not working ..謝謝 – yoni 2010-06-30 15:23:39