问题描述
最近在学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>
解决方案:
怎么解决啊?我也遇到了