如何使C#WCF在局域网中工作? [英] How to make C# WCF work in LAN?

查看:134
本文介绍了如何使C#WCF在局域网中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

各位大家好!



我创建了一个WCF / WPF应用程序。 WCF正在使用Entity Framework从数据库中获取数据。

在我的本地计算机上,一切正常。



但是,怎么能我在局域网中做这项工作?我家里有几台电脑,所以我想在这个应用程序中使用它们。



这就是来自服务的app.config的样子: br />

 <? xml version =   1.0 encoding =   utf-8 ?>  
< configuration >
< configSections >
<! - 有关实体框架配置的更多信息,请访问http://go.microsoft.com/fwlink/?LinkID=237468 - >
< section 名称 = entityFramework type = System.Data .Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version = 4.4.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089 requirePermission = false / >
< ; / configSections >
< system.web >
< ; 编译 debug < span class =code-keyword> =
true / >
< / system.web >
<! - 部署服务库项目时,必须将配置文件的内容添加到主机的
app.config文件中。 System.Configuration不支持库的配置文件。
- >

< system.serviceModel >
< < span class =code-leadattribute> services >
< service name = ISKUService.Service1 >
< host >
< span class =code-keyword>< baseAddresses >
< 添加 baseAddress = http:// localhost:8733 / Design_Time_Addresses / ISKUService / Service1 / / >
< / baseAddresses >
< / host >
<! - 服务端点 - >
<! - 除非完全合格,否则地址为相对于上面提供的基地址 - >
< 端点 地址 = binding = basicHttpBinding 合同 = ISKUService.IService1 >
<! -
部署后,应删除或替换以下标识元素,以反映运行已部署服务的
标识。如果删除,WCF将自动推断出适当的身份

- >

< 身份 >
< dns value = localhost / >
< / identity >
< / endpoint >
<! - < span class =code-keyword> 元数据端点 - >
<! - 服务使用元数据交换端点向客户端描述自己。 - >
<! - < span class =code-keyword> 此端点不使用安全绑定,应在部署之前加以保护或删除 - - >
< endpoint 地址 = mex binding = mexHttpBinding 合同 = IMetadataExchange / >
< / service >
< / services >
< 行为 >
< serviceBehaviors >
< 行为 >
<! - 为避免泄露元数据信息,
在部署之前将以下值设置为false
- >

< serviceMetadata httpGetEnabled = True / >
<! - - 要接收故障中的异常详细信息以进行调试,
将以下值设置为true。在部署
之前设置为false以避免泄露异常信息
- >

< serviceDebug includeExceptionDetailInFaults = 错误 / >
< / behavior >
< / serviceBehaviors >
< ; / behavior >
< / system.serviceModel >
< entityFramework >
< defaultConnectionFactory type = System.Data.Entity.Infrastructure.SqlConnectionFactory,EntityFramework / >
< / entityFramework >
< / configuration >





Thanx!



我尝试了什么:



我试图改变

 <   add     baseAddress   =  http: // localhost:8733 / Design_Time_Addresses / ISKUService / Service1 /    /  >  



进入

 <   add     baseAddress   =  http://192.168.1.13:8733/Design_Time_Addresses/ISKUService/Service1/    /  >  





这是我在另一台电脑上的错误:



< a href =https://s4.postimg.io/otyu519xp/error.jpg> https://s4.postimg.io/otyu519xp/error.jpg [ ^ ]

但没有运气......

解决方案

我建​​议从这里开始:关于如何托管WCF服务的初学者教程(IIS托管和自托管) [ ^ ]



有关详细信息,请参阅: WCF服务发布 [ ^ ]

您在IIS中发布WCF应用程序,它应该可用于您的LAN。要访问WCF,请使用发布它的虚拟地址和端口。另外,请确保端口打开以进行通信


Hello, everybody!

I have created a WCF/WPF application. WCF is using Entity Framework to get data from database.
And on my local computer everything is working just fine.

But, how can I make this work in LAN? I have couple of computers in my home, so I wanted to work in this application on all of them.

This is how app.config from service look like:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="ISKUService.Service1">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/ISKUService/Service1/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="basicHttpBinding" contract="ISKUService.IService1">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the value below to false before deployment -->
          <serviceMetadata httpGetEnabled="True" />
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
</configuration>



Thanx!

What I have tried:

I have tried to change

<add baseAddress="http://localhost:8733/Design_Time_Addresses/ISKUService/Service1/" />


into

<add baseAddress="http://192.168.1.13:8733/Design_Time_Addresses/ISKUService/Service1/" />



This is the error that I get on the other computer:

https://s4.postimg.io/otyu519xp/error.jpg[^]
but no luck...

解决方案

I'd suggest to start here: A Beginner's Tutorial on How to Host a WCF Service (IIS Hosting and Self Hosting)[^]

For further details, please see: WCF Service Publishing[^]


You publish the WCF app in the IIS and it should be available for your LAN. In order to access the WCF, use the virtual address and port where it was published. Also please make sure that the port is open for communication


这篇关于如何使C#WCF在局域网中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆