WCF服务发布的地址中域名能换为ip吗?

问题描述

最近在学WCF,有几个关于地址的问题一直弄不明白。我使用IIS作host,假设服务器地址为10.8.8.8,服务器的主机名为mycoputer,.svc文件的地址在http://localhost/WCF/Service.svc。在服务器本机访问http://localhost/WCF/Service.svc,可以出现帮助页面,提示我用svcutil.exehttp://mycoputer/WCF/Service.svc?wsdl引用服务,这在服务器上没问题,它可以识别自己的域名http://mycoputer,但在别的机器上则无法解析http://mycoputer这个域名,因此也无法引用http://mycoputer/WCF/Service.svc?wsdl。后来我设置了httpGeturl属性,将元数据的httpget地址强行设置为http://10.8.8.8/WCF/Service.svc/meta,则在其他机器上可以用http://10.8.8.8/WCF/Service.svc/meta?wsdl引用服务。但是,操作中的基地址仍然为http://mycoputer/WCF/Service.svc,在其他机器调用服务时会发生异常,我用<host>节添加基地址也不起作用。请问,如何让客户端用ip地址访问WCF服务?

解决方案

解决方案二:
局域网基础知识。参考:http://www.google.cn/search?sourceid=navclient&hl=zh-CN&ie=UTF-8&rlz=1T4GGLS_zh-CNCN263CN263&q=%e5%b1%80%e5%9f%9f%e7%bd%91+dns+host%e6%96%87%e4%bb%b6
解决方案三:
但我们不能强迫客户端修改自己的host文件作域名到地址的映射吧,能不能发布服务时就用ip地址?
解决方案四:
把mycoputer改为IP就可以了啊,没啥特别的设置吧
解决方案五:
是啊,但服务端发布服务时基地址会默认使用主机名而不用ip,那么客户端通过wsdl获得的元数据里都是http://mycomputer的地址,不能让每个客户自己去把他们改为ip吧,这是不是iis设置的问题?
解决方案六:
接分先!
解决方案七:
好像没那么简单,呵呵.
解决方案八:
正在面临这个问题,请问有解决方便了么?
解决方案九:
引用4楼icefireelf的回复:

是啊,但服务端发布服务时基地址会默认使用主机名而不用ip,那么客户端通过wsdl获得的元数据里都是http://mycomputer的地址,不能让每个客户自己去把他们改为ip吧,这是不是iis设置的问题?

主要是你摆弄太多名词术语,造成误会太多。实际上,就一句话:wcf客户端代理对象有个url属性可以在运行时设置。
解决方案十:
在你最初的问题中,你引导出来的意思似乎是:如何解析mycoputer这个域名。
解决方案十一:
1、服务和客户端都用主机的IP肯定没问题2、服务和客户端都用主机的域名时,客户端要能解析这个域名才行,即客户端计算机需加入相应的DNS服务器地址。3、服务用域名、客户端用主机的IP,按理说可以,但是试了N次,得出结论:不行。
解决方案十二:
顶一下,现在我也遇到这个问题,本地的客户端可以正常访问,但远程的客户端则访问即使是改了基地址为IP地址,还是不行不知道是不是需要从IIS上做出设置才行,友情帮顶,等待答案
解决方案十三:
我也遇到了,如果发布的时候用了192.168.0.201来引用wcf服务,那么只能用这个IP地址访问web应用程序,才能访问wcf服务,如果用域名就访问不了,如果发布的时候用了域名来引用wcf服务,那么只能用这个域名访问web应用程序才能访问wcf服务。这个域名和IP地址之间的解析绝对无问题,因为我放别的网站没问题的,IP和域名都能访问。
解决方案十四:
一用静态IP,二注册个DNS
解决方案十五:
wcf做成了服务放在192.168.4.110机器上,如果换了一个IP:192.168.4.119。那么客户端的程序还是要重新引用,然后重新编译啊!才能访问.
解决方案:
这个问题我遇到过需要一个工具转换下具体工具我不记得了,我把转换后的类贴出来这个类放到客户端调用就行了,能配置服务地址//------------------------------------------------------------------------------//<auto-generated>//此代码由工具生成。//运行时版本:4.0.30319.235////对此文件的更改可能会导致不正确的行为,并且如果//重新生成代码,这些更改将会丢失。//</auto-generated>//------------------------------------------------------------------------------////此源代码由wsdl自动生成,Version=4.0.30319.1。//namespaceAppsManagement{usingSystem;usingSystem.Web.Services;usingSystem.Diagnostics;usingSystem.Web.Services.Protocols;usingSystem.ComponentModel;usingSystem.Xml.Serialization;usingSystem.Data;///<remarks/>[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl","4.0.30319.1")][System.Diagnostics.DebuggerStepThroughAttribute()][System.ComponentModel.DesignerCategoryAttribute("code")][System.Web.Services.WebServiceBindingAttribute(Name="CsWebServiceSoap",Namespace="http://localhost/Server")]publicpartialclassCsWebService:System.Web.Services.Protocols.SoapHttpClientProtocol{privateSystem.Threading.SendOrPostCallbackHelloWorldOperationCompleted;privateSystem.Threading.SendOrPostCallbackGetUserInfoOperationCompleted;privateSystem.Threading.SendOrPostCallbackGetCsSoftInfoOperationCompleted;privateSystem.Threading.SendOrPostCallbackGetRarInfoOperationCompleted;///<remarks/>publicCsWebService(){this.Url="http://192.168.1.11/gzir/services/CsWebService.asmx";}publicCsWebService(stringwsURL){this.Url=wsURL;}///<remarks/>publiceventHelloWorldCompletedEventHandlerHelloWorldCompleted;///<remarks/>publiceventGetUserInfoCompletedEventHandlerGetUserInfoCompleted;///<remarks/>publiceventGetCsSoftInfoCompletedEventHandlerGetCsSoftInfoCompleted;///<remarks/>publiceventGetRarInfoCompletedEventHandlerGetRarInfoCompleted;///<remarks/>[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://localhost/Server/HelloWorld",RequestNamespace="http://localhost/Server",ResponseNamespace="http://localhost/Server",Use=System.Web.Services.Description.SoapBindingUse.Literal,ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]publicstringHelloWorld(){object[]results=this.Invoke("HelloWorld",newobject[0]);return((string)(results[0]));}///<remarks/>publicSystem.IAsyncResultBeginHelloWorld(System.AsyncCallbackcallback,objectasyncState){returnthis.BeginInvoke("HelloWorld",newobject[0],callback,asyncState);}///<remarks/>publicstringEndHelloWorld(System.IAsyncResultasyncResult){object[]results=this.EndInvoke(asyncResult);return((string)(results[0]));}///<remarks/>publicvoidHelloWorldAsync(){this.HelloWorldAsync(null);}///<remarks/>publicvoidHelloWorldAsync(objectuserState){if((this.HelloWorldOperationCompleted==null)){this.HelloWorldOperationCompleted=newSystem.Threading.SendOrPostCallback(this.OnHelloWorldOperationCompleted);}this.InvokeAsync("HelloWorld",newobject[0],this.HelloWorldOperationCompleted,userState);}privatevoidOnHelloWorldOperationCompleted(objectarg){if((this.HelloWorldCompleted!=null)){System.Web.Services.Protocols.InvokeCompletedEventArgsinvokeArgs=((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));this.HelloWorldCompleted(this,newHelloWorldCompletedEventArgs(invokeArgs.Results,invokeArgs.Error,invokeArgs.Cancelled,invokeArgs.UserState));}}///<remarks/>[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://localhost/Server/GetUserInfo",RequestNamespace="http://localhost/Server",ResponseNamespace="http://localhost/Server",Use=System.Web.Services.Description.SoapBindingUse.Literal,ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]publicSystem.Data.DataTableGetUserInfo(stringUserName){object[]results=this.Invoke("GetUserInfo",newobject[]{UserName});return((System.Data.DataTable)(results[0]));}///<remarks/>publicSystem.IAsyncResultBeginGetUserInfo(stringUserName,System.AsyncCallbackcallback,objectasyncState){returnthis.BeginInvoke("GetUserInfo",newobject[]{UserName},callback,asyncState);}///<remarks/>publicSystem.Data.DataTableEndGetUserInfo(System.IAsyncResultasyncResult){object[]results=this.EndInvoke(asyncResult);return((System.Data.DataTable)(results[0]));}///<remarks/>publicvoidGetUserInfoAsync(stringUserName){this.GetUserInfoAsync(UserName,null);}内容太长删除一部分}}
解决方案:
就是服务器IIS做个IP地址绑定
解决方案:
可以的,类似下面注释部分做修改就行了。<system.serviceModel><services><servicebehaviorConfiguration="BGManager.Service1Behavior"name="***"><endpointaddress=""binding="basicHttpBinding"bindingConfiguration=""contract="***"><identity><!--<dnsvalue="192.168.0.147"/>--><dnsvalue="webgameseed"/></identity></endpoint><endpointaddress="mex"binding="mexHttpBinding"contract="IMetadataExchange"/></service><servicebehaviorConfiguration="BGManager.Service1Behavior"name="***"><endpointaddress=""binding="basicHttpBinding"bindingConfiguration=""contract="***"><identity><!--<dnsvalue="192.168.0.147"/>--><dnsvalue="webgameseed"/></identity></endpoint><endpointaddress="mex"binding="mexHttpBinding"contract="IMetadataExchange"/></service></services></system.serviceModel>

解决方案:
配置文件中做修改:<!--<dnsvalue="192.168.0.147"/>-->==》<dnsvalue="webgameseed"/><system.serviceModel><services><servicebehaviorConfiguration="BGManager.Service1Behavior"name="***"><endpointaddress=""binding="basicHttpBinding"bindingConfiguration=""contract="***"><identity><!--<dnsvalue="192.168.0.147"/>--><dnsvalue="webgameseed"/></identity></endpoint><endpointaddress="mex"binding="mexHttpBinding"contract="IMetadataExchange"/></service><servicebehaviorConfiguration="BGManager.Service1Behavior"name="***"><endpointaddress=""binding="basicHttpBinding"bindingConfiguration=""contract="***"><identity><!--<dnsvalue="192.168.0.147"/>--><dnsvalue="webgameseed"/></identity></endpoint><endpointaddress="mex"binding="mexHttpBinding"contract="IMetadataExchange"/></service></services></system.serviceModel>

解决方案:
配置文件中做修改:<!--<dnsvalue="192.168.0.147"/>-->==》<dnsvalue="webgameseed"/><system.serviceModel><services><servicebehaviorConfiguration="BGManager.Service1Behavior"name="***"><endpointaddress=""binding="basicHttpBinding"bindingConfiguration=""contract="***"><identity><!--<dnsvalue="192.168.0.147"/>--><dnsvalue="webgameseed"/></identity></endpoint><endpointaddress="mex"binding="mexHttpBinding"contract="IMetadataExchange"/></service><servicebehaviorConfiguration="BGManager.Service1Behavior"name="***"><endpointaddress=""binding="basicHttpBinding"bindingConfiguration=""contract="***"><identity><!--<dnsvalue="192.168.0.147"/>--><dnsvalue="webgameseed"/></identity></endpoint><endpointaddress="mex"binding="mexHttpBinding"contract="IMetadataExchange"/></service></services></system.serviceModel>

解决方案:
怎么解决啊?我也遇到了

时间: 2024-08-03 09:34:29

WCF服务发布的地址中域名能换为ip吗?的相关文章

WCF服务发布到IIS时候,只能根据hostname访问,不能根据IP地址访问的解决办法

本文转载:http://www.cnblogs.com/deerbox/archive/2013/05/13/3076248.html 环境: VS2010 sp1,.net framework 4.0,windows server 2003 x64 ,iis 6.0 症状: WCF开发测试,本地调用都正常.发布后,在浏览器中访问http://ip/Service.svc,可以正常浏览,但svcutil.exe 显示的是域名:http://域名/Service.svc. 在VS中,添加服务引用,

WCF服务端运行时架构体系详解[下篇]

作为WCF中一个核心概念,终结点在不同的语境中实际上指代不同的对象.站在服务描述的角度,我们所说的终结点实际上是指ServiceEndpoint对象.如果站在WCF服务端运行时框架来说,终结点实际上指代的是终结点分发器(EndpointDispatcher).而ServiceEndpoint与EndpointDispatcher是一一匹配的,并且前者是创建后者的基础.而终结点分发器具有自己的运行,即分发运行时(DispatchRuntime). 目录 一.终结点分发器(EndpointDispa

怎样才可以把内网服务发布到公网

很多用户在自己的机器中架设起网站.FTP服务,甚至是小型http://www.aliyun.com/zixun/aggregation/12489.html">邮件服务器,但这些网络服务由于防火墙或处于内网的缘故,只能供自己或 同一局域网内的用户使用.如果你想让这些网络服务被更多的人分享, 其实可以利用防火墙将这些服务发布到互联网中,如何发布呢? 下面,就针对Windows 19803.html">XP系统的Windows防火墙的"服务发布"功能,介绍几

WinForm企业应用框架设计【二】团队内部的约定和客户端按约定识别WCF服务

本系列第一篇发出来之后,与钧梓昊逑讨论了一些问题,现整理出来 (钧梓昊逑是我的入门老师~非常牛的技术天才~现在开始涉足西洋乐器领域~希望他能早日超过贝多芬~为山寨党众同仁争光~) 一:关于职责问题 客户端的主要职责负责呈现,不宜有过多的业务逻辑 与业务相关的代码和访问数据库相关的代码放在服务器端 与呈现相关的代码放在客户端  至于哪些代码是与业务相关的,哪些代码是与呈现相关的 呈现的代码是不是包含了业务,业务的代码是不是牵涉到呈现 这属于边界划分的问题,仁者见仁~智者见智~也要根据项目具体问题具

WF4.0实战(三):WCF服务

这篇文章,通过一个简单的WCF交互,讲解一下WF4.0中一组重要活动:Messaging,它包括:Receive.ReceiveAndSendReply.Send. SendAndReceiveReply.这里将详细讲解ReceiveAndSendReply和SendAndReceiveReply两个活动的配置以及使用,以及它与普通的WCF的区别 . 如果你了解WCF,你一定知道WCF可以缩略为ABC.A :Address (服务在哪里?),B: Binding (怎么才能访问服务?),C: C

提高WCF服务并发能力的简单处理办法

步骤:1.把同样的WCF服务,在多个端口上"启动"(即同时运行多个wcf的实例,但每个实例都监听不同的端口) 2.用svcutil.exe生成的代理类,里面有N多构造函数的重载版本,观察一下类似下面的这个版本 public AstroServiceClient(string endpointConfigurationName) :             base(endpointConfigurationName)    {    } 即传入配置名生与代码类的实例,我们在web.co

WCF随客户端软件一起发布,客户端自动识别WCF服务地址,不通过配置文件绑定WCF服务,客户端动态获取版本号

WCF发布到IIS,并有相应的SVC宿主文件客户端软件通过CLICK ONCE发布到WCF的相同目录下本例实现了:客户端自动发现WCF服务的功能 1 不通过配置文件绑定WCF服务 代码 ICallCenter proxy = null; BasicHttpBinding binding = new BasicHttpBinding();EndpointAddress address = new EndpointAddress(AppDeploymentUtils.GetWcfUri());bin

如何将WCF服务角色发布到托管服务中

Windows Azure是一个基于Silverlight的软件,它的开发门户现在也已经焕然一新了.它的所有信息,所有的操作都可以在一个页面中完成.使用这个全新的门户,从配置guest操作系统到停止或重启一个服务,几乎在一个页面上,就可以把所有的事情完成.在一些文章中我们学习到如何使用WCF Service Web Role. 同时子在一个托管服务中托管一个WCF服务角色差不多是和托管一个ASP.Net Web Role等同的.下面就介绍下如何将WCF服务角色发布到托管服务中的步骤 1,登录到A

WCF服务中元数据的地址问题

初用WCF的朋友可能会遇到这样的问题,就是在使用svcutil.exe生成proxy和config的时候,或者利用add service reference添加引用的时候,部署的WCF服务到底它的metadata是什么.或者换句话说,svcutil的URL参数,以及添加服务引用时候的那个Address,到底应该填什么. 在这里我用两个最常用的Binding方式,WSHttpBinding和NetTcpBinding,分别以实际的例子来进行说明. 建立服务契约 在这里就从MSDN上抄一个四则运算的