简体   繁体   中英

How to publish WCF service in internet (hosted in wnd service)

I have a windows service on my laptop, which hosts a WCF service. I would like to use these service on my ASP.NET website, which is on external ASP.NET server.

Could you help me, how to do this?

Is it necessary a specific laptop configuration for that? What should I configure?

And binding, what type will adequate? .. Right now, I've got:

  <service behaviorConfiguration="WcfServices.InfoBehavior" name="MyProgram.WcfServices.Info.Info">
    <endpoint address="" binding="wsHttpBinding" contract="MyProgram.WcfServices.Info.IInfo">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8732/Info/" />
      </baseAddresses>
    </host>
  </service>

UPDATE: Right now, my client app is still on my laptop (it is not publish yet).. This is my client code:

<client>
  <endpoint address="http://localhost:8732/Info/" binding="wsHttpBinding"
    bindingConfiguration="WSHttpBinding_IInfo" contract="ServiceInfo.IInfo"
    name="WSHttpBinding_IInfo">
    <identity>
      <dns value="localhost" />
    </identity>
  </endpoint>
</client>

I don't know, what binding use.. what port, what settings should be changed on my laptop?

Unless your laptop has its own fixed IP address exposed externally (most unlikely) I think you will find it hard to do this directly.

You might consider using Azure Service Bus to broker message exchanges: I believe this is one way to solve the problem of accessing a service hosted on a non-constant IP address or behind a firewall/NAT.

Or you could consider changing your design to turn things the other way around. That is, when it is connected and running, your laptop service connects to a service hosted on the ASP.NET box, over a duplex binding, with your current service contract as the callback contract.

如果您有通过ServiceHost托管的便携式计算机上运行的WCF服务,则需要在ASP.NET web.config文件中复制该配置,并添加引用到您的接口的“ service.svc”文件服务。

You should change localhost with real external facing IP address of your laptop and it could work if your router at home has no firewall. Change it in both client and server endpoint address.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM