首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从另一台计算机访问wcf服务?

如何从另一台计算机访问wcf服务?
EN

Stack Overflow用户
提问于 2013-09-12 13:29:36
回答 2查看 5.3K关注 0票数 1

我有一个wcf服务,并将其安装为windows服务。我可以从192.168.2.6机器访问这项服务:

代码语言:javascript
复制
"net.tcp://192.168.2.5:2025/Services/mex".

我想使用静态ip和端口从另一台计算机访问此服务。

如何访问此服务?

我尝试连接net.tcp://staticIp:port/Services/mex,得到了错误:

代码语言:javascript
复制
Metadata contains a reference that cannot be resolved: 'net.tcp://[staticIP]:[port]/Services/mex'.If the service is defined in the current solution, try building the solution and adding the service reference again.

(我把我的港口导航到2025年的内港)

我的配置:

代码语言:javascript
复制
<system.serviceModel>
<diagnostics>
  <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
</diagnostics>
<bindings>
  <netTcpBinding>
    <binding name="NetTcpBinding_IServices" />
  </netTcpBinding>
</bindings>
<client>
  <endpoint address="net.tcp://192.168.2.5:2025/Services" binding="netTcpBinding"
    bindingConfiguration="NetTcpBinding_IServices" contract="myServices.IServices"
    name="NetTcpBinding_IServices">
    <!--<identity>
      <dns value="localhost" />
    </identity>-->
  </endpoint>
</client>
<services>
  <service name="F8ShadowWcfLib.Services">
    <endpoint address="" binding="netTcpBinding" bindingConfiguration=""
      contract="F8ShadowWcfLib.IServices">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
      contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://192.168.2.5:2025/Services" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="false"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

Edit1:

我从config中删除标记,并在运行时添加它。

代码语言:javascript
复制
myService.ServicesClient myServ = new myService.ServicesClient();
            EndpointAddress myEndpointAdd = new EndpointAddress(new Uri("net.tcp://[staticIP]:[port]/Services") ,
                                                EndpointIdentity.CreateDnsIdentity("net.tcp://f8srv.f8.com.tr:2299/Services"));

myServ.Endpoint.Address = myEndpointAdd;

我遇到了不同的错误:服务器拒绝了客户端凭据。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-09-14 14:08:19

若要允许分离连接,请设置AddressFilterMode : Any,并同时设置服务和客户端。

这篇关于identy设置的文章:

http://msdn.microsoft.com/en-us/library/ms733130.aspx

代码语言:javascript
复制
 [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]
   public class Services : IServices
   {
        .
        .
        .
   }
票数 0
EN

Stack Overflow用户

发布于 2013-09-12 16:07:45

这个问题可能与这一部分有关:

代码语言:javascript
复制
<identity>
    <dns value="localhost" />
</identity>

这种工作是在本地工作的,因为本地主机在本地是有意义的,但在整个网络中却没有意义。

您可以通过多种方式验证此标识,例如指定运行服务的用户的UPN (用户主体名称)或运行该服务的服务器的SPN (Server主体名称)(尽管为此您必须注册一个SPN)。

这篇文章应该稍微解释一下:

http://msdn.microsoft.com/en-us/library/ms733130.aspx

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18765713

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档