简体   繁体   中英

Using Static WAN IP Address for WCF in IIS

I have set up a WCF service hosted in IIS. The server that it is hosted on does not have a DNS Name (no domain), just an external static WAN IP address.

When I try to connect to the service in either iOS or Windows client using MEX to generate proxies, it uses the domain name which cannot be resolved and fails.

The WSDL document contains links that could not be resolved. - There was an error downloading ' https://blah.com.au/NimThaiService.svc?xsd=xsd3 '. - The remote name could not be resolved: 'blah.com.au'

How can I change my Web config file or configure IIS so that instead of using the domain name it uses the static IP.

I need the MEX to be https://123.123.123.123/NimThaiService.svc

I've tried to follow directions in other articles. For example one suggests to add <useRequestHeadersForMetadataAddress /> . But when I do that I get an error saying that the resource cannot be found.

My Web config file is as follows:

<?xml version="1.0"?>

<configuration>

    <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
    </system.web>

    <system.serviceModel>
      <behaviors>
        <serviceBehaviors>
          <behavior>
            <serviceMetadata httpsGetEnabled="true"/>
            <serviceCredentials>
                <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="NimThaiService.Authenticator, NimThaiService" />
            </serviceCredentials>
          </behavior>
        </serviceBehaviors>        
      </behaviors>

      <services>
        <service name="NimThaiService.NimThaiService">
          <endpoint address="https://mystaticwanipaddress:443/NimThaiService.svc" binding="basicHttpBinding" contract="NimThaiService.INimThaiService" bindingConfiguration="secureHttpBinding">
            <identity>
              <dns value="localhost" />
            </identity>
          </endpoint>
          <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange">
            <identity>
              <dns value="mystaticwanipaddress" />
            </identity>
          </endpoint>
        </service>        
      </services>

      <bindings>
        <basicHttpBinding>
          <binding name="secureHttpBinding">
            <security mode="Transport">
          <transport clientCredentialType="Basic" />
          <message clientCredentialType="UserName"/>
            </security>
          </binding>
        </basicHttpBinding>
      </bindings>

    </system.serviceModel>  

</configuration>

After some more research I managed to fix this by adding an attribute to the serviceMetadata node.

I needed to add the "httpsGetUrl" attribute as follows:

<serviceMetadata httpsGetEnabled="true" httpsGetUrl="http://mystaticwanipaddress/NimThaiService.svc/basic"  />

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