Using Static WAN IP Address for WCF in IIS - wcf

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" />

Related

How enable http and https with wcf service?

I need publish a wcf service, and this should be accessed with Http and Https protocols.
I tried to configure this in my server, but the problem with is that only one of this protocols can work.
Is it possible?
This is my Web.config code:
<bindings>
<basicHttpBinding>
<binding name="basicHttpBindingConfiguration">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviorConfiguration">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceBehaviorConfiguration" >
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicHttpBindingConfiguration" name="TestSvc" contract="ServiceTest.ITest" />
</service>
</services>
It's possible, but in a way you might not expect. You host your service on HTTPS. Then create another site on the same pool. This site is HTTP and it contains only web.config file looking like this
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="true" destination="https://your_https_url" exactDestination="true" childOnly="false" />
</system.webServer>
</configuration>
Now every time someone tries to use the HTTP site will be automatically redirected to HTTPS.
Try using multiple endpoints for same service one with basicHttpBindind and one with wsHttpBinding
<service name="NorthwindServices.Services.CustomerService"
behaviorConfiguration ="ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:7741/NorthwindServices/Services
/CustomerService" />
<add baseAddress="https://localhost:4512/Services/CustomerService" />
</baseAddresses>
</host>
<endpoint address ="" binding="wsHttpBinding"
contract="NorthwindServices.ServiceContracts.ICustomerService"
bindingNamespace = "http://dotnetmentors.com/services/customer" />
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange"/>
<endpoint address ="" binding ="basicHttpBinding"
contract ="NorthwindServices.ServiceContracts.ICustomerService"
bindingNamespace = "http://dotnetmentors.com/services/customer" />
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>

WCF related - System.ServiceModel.FaultException: The message could not be processed

This is similar to: http://social.msdn.microsoft.com/Forums/vstudio/en-US/71c31684-1ce7-4fd9-bf24-674e6dc707bf/the-message-could-not-be-processed?forum=wcf
However, I did not forget an entry like that person did yet I still get the same error.
I get:
System.ServiceModel.FaultException: The message could not be processed. This is most likely because the action 'http://tempuri.org/IBackupServerService/DeleteBySpaceIdProcess' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.
Note: I'm hosting the service from a console app on a server and then calling the service from a web app located on another server.
My client web.config file looks like: (Note: the "IP address" and "userPrincipalName" are both fictitious for this posting.)
<!-- Specifies the version of WCF to use. -->
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IBackupServerService" >
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://999.999.999.999:8000/Application/BackupServerServiceLibrary/BackupServerService/BackupServerService"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IBackupServerService"
contract="ServiceReference1.IBackupServerService" name="WSHttpBinding_IBackupServerService">
<identity>
<userPrincipalName value="AAAAA5-415-B\jbrown" />
</identity>
</endpoint>
</client>
</system.serviceModel>
My service app.config looks like:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="BackupServerServiceLibrary.BackupServerService">
<host>
<baseAddresses>
<add baseAddress = "/BackupServerServiceLibrary/BackupServerService/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<endpoint address="" binding="wsHttpBinding"
contract="BackupServerServiceLibrary.IBackupServerService"
bindingConfiguration="NoSecurity">
<!-- 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. -->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="NoSecurity">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Any ideas?

Error 500.19 local IIS

I have a wcf service.
It use local IIS server.
My web.config is :
<?xml version="1.0"?>
<configuration>
<system.web>
<authentication mode="Windows"/>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="InstantMessagingBinding" closeTimeout="00:00:45">
<textMessageEncoding>
<readerQuotas maxStringContentLength="200000" maxArrayLength="200000" />
</textMessageEncoding>
<httpTransport keepAliveEnabled="false" maxReceivedMessageSize="200000" authenticationScheme="Ntlm"/>
</binding>
</customBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="InstantMessagingBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="Isima.InstantMessaging.WcfService.ContactService" behaviorConfiguration="InstantMessagingBehavior">
<endpoint address=""
binding="customBinding" bindingConfiguration="InstantMessagingBinding"
contract="Isima.InstantMessaging.WcfService.IContactService" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
And when I run my service, I get an error
This error is about "This problem can occur when the specified part of the IIS configuration file is locked at a higher level configuration."
Why this error?
Check, if all application development components are installed for IIS. e.g. .NET and ASP.NET. See the add/remove windows-feature dialog in the control panel and check the installed IIS components.
I always install all development components (ASP.NET, ...).

Changing WCF service to require SSL

I have a WCF service which was running fine on a http binding. I've tried to update this to use SSL but i am getting the following error:
"Could not find a base address that matches scheme http for the endpoint with binding WSHttpBinding. Registered base address schemes are [https]."
This only occurs when i set the site to "Require SSL" in IIS 7.5 if I uncheck it it works fine.
Here's my config
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior" >
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
<!-- 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" />
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="wsHttpEndpointBinding">
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ServiceBehavior" name="WcfService1.Service1">
<host>
<baseAddresses>
<add baseAddress="http://localhost/WcfService1/"/>
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" bindingConfiguration=""
name="wsHttpEndpoint" contract="WcfService1.IService1" />
<endpoint address="mex" binding="mexHttpsBinding" bindingConfiguration=""
name="MexHttpsBindingEndpoint" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
I've tried allsorts and nothing seems to get me there, any help is greatly appreciated!
Modify your binding configuration:
<bindings>
<wsHttpBinding>
<binding name="wsHttpEndpointBinding">
<security mode="Transport" />
</binding>
</wsHttpBinding>
</bindings>
And reference that configuration in your endpoint by setting its bindingConfiguration attribute to the name of configuration.
<endpoint address="" binding="wsHttpBinding"
bindingConfiguration="wsHttpEndpointBinding"
name="wsHttpEndpoint" contract="WcfService1.IService1" />
You can also delete the host section with base address because it is not used when hosting in IIS.
In addition to changing the binding configuration settings (as Ladislav mentioned)... Change HTTP in the base address to HTTPS.

Could not find a base address that matches scheme HTTPS error in IIS-hosted WCF

I almost have everything set up to use my WCF service over https. IIS application is up and running, I can read the svc and wsdl at localhost. So I went back to Visual Studio and tried to write a Client that can call the service. When adding the ServiceReference I get the following error:
Could not find a base address that matches scheme https for the endpoint with binding MetadataExchangeHttpsBinding. Registered base address schemes are [http].
I've tried with the built-in development server and with IIS Express also. They both gave the same error.
Here's my web.config:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="SmartCook2.Server.ISmartCookServiceBehavior">
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service behaviorConfiguration="SmartCook2.Server.ISmartCookServiceBehavior"
name="SmartCook2.Server.SmartCookService">
<endpoint address="https://localhost:6344/SmartCookService.svc"
binding="wsHttpBinding" bindingConfiguration="TransportSecurity"
contract="SmartCook2.Server.ISmartCookService" />
<endpoint address="mex" binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
What am I doing wrong?
It seems VS didn't discover the address right, since it left out the application part. So the correct address for the service reference is :
https://localhost/IISHostedSmartCook/SmartCookService.svc