我是使用Web服務的新手。遠程計算機的本地Web服務訪問(本地主機與IP地址)
我使用visual studio 2017在C#中創建了一個Web服務(該服務是一個.svc文件)。
此Web服務發佈到遠程計算機上的文件夾。
當我連接到遠程機器,我可以運行帶有URL的Web服務:
http://localhost:1869/ServiceName.svc/
但是,當我試圖從我的計算機上運行的Web服務,我試圖修改通過用ip地址替換'localhost'來實現url,但它不起作用。
是否可以遠程訪問本地Web服務?
如果沒有,發佈Web服務的最佳方式是什麼,以便它可以遠程訪問?
感謝您的幫助!
-EDIT-
請參閱下面的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上? – Digvijay
感謝您的回答!它是自我託管的。 – yoann
你使用basicHttpBinding,wsHttpBinding等什麼綁定?如果你可以顯示一些代碼 - 你試過的東西等等會很棒。 – Digvijay