简体   繁体   中英

local web service access from remote computer (localhost vs. ip address)

I'm new to using web services.

I created a web service in C# using visual studio 2017 (the service is a .svc file).

This web service is published to a folder on a remote machine.

When I connect to the remote machine, I can run the web service with the url:

http://localhost:1869/ServiceName.svc/

But when I'm trying to run the web service from my computer, I tried to modify the url by replacing 'localhost' with the ip address but it doesn't work.

Is it possible to access remotely a local web service?

If not, what is the best way to publish the web service so that it can be accessed remotely?

Thanks for your help!

-EDIT-

See Web.config code below.

I tried to create a web server on the remote machine and place the Visual Studio solution project / compile it in C:\\inetpub\\wwwroot, did not help

<?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>

Thanks for your help!

I was able to make it work following instruction from there: link

It boils down to configuring IIS and the website correctly.

The key questions to answer were:

Have you enabled basic authentication at the server level in IIS?

Have you enabled remote connections to the Web Management Service?

Have you started the Web Management Service?

Are there management service delegation rules in place?

Does your firewall allow incoming connections to the server on TCP port 8172?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM