2010-06-30 72 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