从其他计算机访问WCF服务时,我收到以下错误
http://localhost:14329/Service1.svc没有可以接受该消息的端点。这通常是由不正确的地址或SOAP操作引起的
这是我服务的 web.config 文件
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
这是我的app.config文件代码,我将托管服务
<system.serviceModel> <behaviors> <serviceBehaviors>
<behavior name="maxBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors> </behaviors> <services> <service behaviorConfiguration="maxBehavior" name="NILSevice.Service1">
<endpoint address="Service1" binding="basicHttpBinding" contract="NILSevice.IService1"/> <host>
<baseAddresses>
<add baseAddress="http://localhost:8080" />
</baseAddresses></host> </service> </services> <serviceHostingEnvironment multipleSiteBindingsEnabled="true"> </serviceHostingEnvironment></system.serviceModel>
这是我的客户端app.config文件代码
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:14329/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="NILServiceReference.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
我是WCF服务编程的新手。我想使用LAN连接从一台机器访问服务到另一台机器。我试过上面的代码,但得到了例外。请帮我解决这个问题。提前致谢
答案 0 :(得分:0)
从您的客户端配置文件:
<client>
<endpoint address="http://localhost:14329/Service1.svc"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1"
contract="NILServiceReference.IService1"
name="BasicHttpBinding_IService1" />
</client>
localhost
告诉客户端在客户端所在的同一台机器上查找服务。由于您尝试在其他计算机上访问该服务,因此无法正常工作。
将localhost
替换为服务所在的服务器名称。例如,如果机器的名称是&#34; MyBigBadServer&#34;,那么它将是:
http://MyBigBadServer:14329/Service1.svc
答案 1 :(得分:0)
到客户端的地址, 你试过使用服务器的hostname \ computername \ ipaddress吗?而不是使用localhost?请看下面的代码...希望这可以解决您的问题
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://YOURSERVER||IP||HOSTNAME||COMPUTERNAME:14329/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="NILServiceReference.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
答案 2 :(得分:0)
每当您遇到WCF端点问题时,我建议您打开WCF日志记录。这可以在服务器端,客户端或两者上完成。
您可以通过相应修改app.config文件(或web.config文件,具体取决于您托管WCF的方式)来实现。
示例,添加此配置部分:
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="sdt"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="MyWcfLogFile.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="sdt"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="MyWcfLogFile.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
这将生成详细的XML文件。要更轻松地查看内容,请从here安装SvcTraceViewer。
这通常可以节省大量时间。您不仅可以查看所有流量和错误,还可以诊断错误并查看错误消息,否则无法轻松获取,例如有关序列化问题或警告的详细信息。