【发布时间】:2017-04-20 21:53:38
【问题描述】:
我是使用网络服务的新手。
我使用 Visual Studio 2017 在 C# 中创建了一个 Web 服务(该服务是一个 .svc 文件)。
此 Web 服务已发布到远程计算机上的文件夹中。
当我连接到远程机器时,我可以使用 url 运行 web 服务:
http://localhost:1869/ServiceName.svc/
但是当我尝试从我的计算机运行 Web 服务时,我尝试通过将 'localhost' 替换为 ip 地址来修改 url,但它不起作用。
是否可以远程访问本地网络服务?
如果没有,发布 Web 服务以便远程访问它的最佳方式是什么?
感谢您的帮助!
-编辑-
请参阅下面的 Web.config 代码。
我尝试在远程机器上创建一个 Web 服务器并将 Visual Studio 解决方案项目 / 编译到 C:\inetpub\wwwroot 中,没有帮助
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="RsConnString" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|RestDB.mdf;User Instance=true" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web">
<!--
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.
-->
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above 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>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data></configuration>
【问题讨论】:
-
这取决于您托管服务的方式。它是自托管的,还是在 iis 上的?
-
感谢您的回答!它是自托管的。
-
您使用的是什么绑定 basicHttpBinding 、 wsHttpBinding 等?如果你能展示一些代码——你已经尝试过的等等,那就太好了。
-
感谢 Digvijay 的帮助!我发布了 Web.config 代码
-
你没有提供任何地址来监听(
address=""在你的配置中)并且没有提供任何基地址
标签: c# web-services wcf