WCF Service hosting in IIS and accessing it using Static IP - performance

I am hosting a WCF service in IIS , it works fine on single system, but when I am trying to access it using remote machine(my system has static ip), it ask me username and password,
when I provide that using computer credentials , it doesn't accept it
Picture 1 shows that figure,
<?xml version="1.0"?>
<bindings>
<basicHttpBinding>
<binding name="Service1Soap">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="None"
realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="WCF_Static.WCF_Service" behaviorConfiguration="maxBehaviour">
<endpoint address="staticip" binding="basicHttpBinding" contract="WCF_Static.IWCF_Service" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost/8080"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="maxBehaviour">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
On Client side proxy I am using
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IWCF_Service" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://123.123.123.123/Alias/Service.svc/staticip"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWCF_Service"
contract="ServiceReference1.IWCF_Service" name="BasicHttpBinding_IWCF_Service" />
</client>
</system.serviceModel>
</configuration>
Refereed links here
Thanks,

Found ! ! :)
deploy service as http://localhost/abc/Service1.svc?wsdl or (http://127.0.0.1/abc/Service1.svc?wsdl) in IIS, on client side add service reference as http://localhost/abc/Service1.svc?wsdl or http://127.0.0.1/abc/Service1.svc?wsdl ,
but in appconfig on client side
change the localhost or 127.0.0.1 to your ip address where actual WCF service is running.
in endpoint like this
endpoint address="http://123.123.123.123/max/Service.svc/static"

Related

publishing web service on 3 different IIS gets different result,Metadata publishing for this service is currently disabled

I am programming a web service . When I publish the web service on Server1 (Windows 2012 With IIS 8),it works fine,but if I publish on Server2 (Windows 2012 With IIS 8), it gives following error
Metadata publishing for this service is currently disabled.
I have tested on Server3 (Windows 2019 With IIS 10), I get the above error
it seems that it might be the IIS setting , because in server1 it is working fine.
This is the web.Config of the service
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="ECartContext" connectionString="metadata=res://*/ECartModel.csdl|res://*/ECartModel.ssdl|res://*/ECartModel.msl;provider=System.Data.SqlClient;provider connection string="data source=databaseServer;initial catalog=ECart;integrated security=True;Connection Timeout=30;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ManagementServiceBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior>
<dataContractSerializer maxItemsInObjectGraph="2147483646" />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<basicHttpBinding>
<binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" >
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="2147483648" />
</requestFiltering>
</security>
</system.webServer>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "c:\log\Traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>
</configuration>
with this config the service works on Server1 only, not Server2 and Server3
how can I check the problem?
You need to add the endpoint in the servicemodel:
<services>
<service name="WcfService2.Service1" behaviorConfiguration="ManagementServiceBehaviour">
<endpoint address="" contract="WcfService2.IService1" binding="basicHttpBinding"></endpoint>
</service>
</services>
I suspect that you have an endpoint in server1 but there is no endpoint in serve2 and server3.

WCF Service, the type provided as the service attribute values...could not be found

I have this issue a long time ago and just cannot recall how to resolve it or perphaps its something new. I created a WCF service which I will later use in web application that calls the WCF service amongst others from a remote location. Right now I am trying to host in IIS and even tried the WCFTestClient. The error I get when I try to browse to the service; is the following:
The type MyService.Service1 provided as the Service attribute
value in the ServiceHost directive, or provided in the
configuration element system.serviceModel/serviceHostingEnvironment/
serviceActivations could not be found.
I figured its probably my web.config file but I cannot see whats wrong:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<webHttpBinding>
<binding name="webHttpBinding" crossDomainScriptAccessEnabled="false" />
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="webHttpBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="webHttpBehavior" name="WcfInstanceRules2.Service1">
<endpoint address=""
binding="webHttpBinding"
contract="WcfRules2.IServiceS" behaviorConfiguration="web"/>
<endpoint address="mex"
binding="webHttpBinding" contract="IMetadataExchange"></endpoint>
</service>
</services>
I would like this to be eventually a rest service delivering data in json format.
Check your .svc file and see what service it's referencing - probably MyService.Service1, which doesn't exist in your config. It looks like it should be referencing WcfInstanceRules2.Service1.

Getting HTTPS to Work with WCF and a Windows Service

I tried updating the App.config files for the client and service for the MS sample applications in WF_WCF_Samples\WCF\Basic\Services\Hosting\WindowsService\CS\WindowsService.sln so that secure bindings were used but when the client makes the call to the service method an exception is thrown
"An error occurred while making the HTTP request to https:// .... /servicemodelsamples/service. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server."
Inner exception "The underlying connection was closed: An unexpected error occurred on a send"
As far as I can see both the server and client configs match and use Transport security mode and the mex endpoint now uses mexHttpsBinding rather than mexHttpBinding with the service behaviour appropriately enabled.
Can someone tell me what is missing or incorrect as I have tried numerous tweaks with no success?
Thanks
The server and client configs are
<?xml version="1.0"?>
<!--Copyright (c) Microsoft Corporation. All Rights Reserved.-->
<configuration>
<system.serviceModel>
<services>
<service name="Microsoft.Samples.WindowsService.WcfCalculatorService">
<host>
<baseAddresses>
<add baseAddress="https://localhost:8000/ServiceModelSamples/service"/>
</baseAddresses>
</host>
<!-- This endpoint is exposed at the base address provided by host: https://localhost:8000/ServiceModelSamples/service -->
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="https" contract="Microsoft.Samples.WindowsService.ICalculator"/>
<!-- The mex endpoint is exposed at https://localhost:8000/ServiceModelSamples/service/mex -->
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<!-- Configure BasicHttp binding with Transport security mode and clientCredentialType as None -->
<binding name="https">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<!-- For debugging purposes set the includeExceptionDetailInFaults attribute to true -->
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
and
<?xml version="1.0"?>
<!--Copyright (c) Microsoft Corporation. All Rights Reserved.-->
<configuration>
<system.serviceModel>
<client>
<endpoint name="" address="https://localhost:8000/servicemodelsamples/service" binding="basicHttpBinding" bindingConfiguration="Binding1" contract="Microsoft.Samples.WindowsService.ICalculator"/>
</client>
<bindings>
<basicHttpBinding>
<!-- Configure BasicHttp binding with Transport security mode and clientCredentialType as None -->
<binding name="Binding1">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
mex cant be https
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
change to
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

how to configure HTTPS and HTTP binding for Ajax Enabled WCF web service

I encountered an errror during the accessing of my web service in https site.
i think this is a configuration error because its looking for an https binding.
here is the web.config of the web service:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
<services>
<service name="WebService.ListViewWebService" behaviorConfiguration="WebService.ListViewWebServiceBehavior">
<endpoint address=""
behaviorConfiguration="WebService.ListViewWebServiceAjaxBehavior"
binding="webHttpBinding"
contract="WebService.IListViewWebService"/>
<endpoint address="https://win-d741qhlbivf:13241/services/DPT/_vti_bin/DPT.WebService/ListViewWebService.svc"
behaviorConfiguration="WebService.ListViewWebServiceAjaxBehavior1"
binding="webHttpsBinding"
contract="WebService.IListViewWebService2"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="webHttpBinding">
<security mode="None" />
</binding>
<binding name="webHttpsBinding">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="WebService.ListViewWebServiceAjaxBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="WebService.ListViewWebServiceBehavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
thanks for the help in advance.
Also, I am not sure if this has something to do with the issue but the web application hosted in a cloud environment...do i need a special configuration for that?...
thanks again..
One of my tutorials will help you:
http://netpl.blogspot.com/2010/05/how-to-programmatically-configure-ssl.html
The tutorial starts with the declarative configuration and then shows how to create binding/endpoints programatically.
This config will respond to requests in HTTP and HTTPS , note that the ports are different and have to match what the host is expecting (in this case it happens to be iis)
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment minFreeMemoryPercentageToActivateService="0" />
<services>
<service name="KPIGetter_Library.KPIGetter">
<endpoint address=""
behaviorConfiguration="restfulBehaviour"
binding="webHttpBinding"
bindingConfiguration="webHttpBindingWithJsonP"
contract="KPIGetter_Library.IKpiGetter" />
<endpoint address=""
behaviorConfiguration="restfulBehaviour"
binding="webHttpBinding"
bindingConfiguration="webHttpsBindingWithJsonP"
contract="KPIGetter_Library.IKpiGetter" />
<host>
<baseAddresses>
<add baseAddress="http://hodbd05:8000/kpigetter" />
<add baseAddress="https://hodbd05:8001/kpigetter" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="restfulBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="webHttpBinding" scheme="http" />
</protocolMapping>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingWithJsonP" crossDomainScriptAccessEnabled="true">
<security mode="None" />
</binding>
<binding name="webHttpsBindingWithJsonP" crossDomainScriptAccessEnabled="true">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
An important issue is that you should use webHttpBinding and not the basicHttpBinding for ajax-enabled WCF services.
A simple working example is found here: Scott's blog on asp.net

Hosting the same WCF Service in IIS and in Windows Service

I am trying to decide on an architecture for a change in my web service. I need to make a WCF service. I want to make only one service and then host it either in the IIS or in a Windows service. Is this even possible, making this kind of reuse of a WCF Service? How would I go about doing this? The scenario is that some of our customers do not have access to start a Windows service but can install a WCF in the IIS.
Thank you in advance.
A WCF service is simply an assembly that abides by the WCF hosting interface and then provides a client interface that allows it to be accessed.
Hosting a WCF service occurs equally in IIS, Windows service, WinForm application, or a console application. It truly doesn't matter.
The client interface remains unchanged, although how the interface is exposed might change depending on hosting scenario. For example, you'll probably use one the http bindings in the IIS case, but might use TCP binding for Windows services. These bindings can be defined in the config file, so the code doesn't necessarily have to change to accommodate being hosted one way or the other.
In short, creating the WCF service should be independent of how it will eventually be hosted. For ease of maintenance on your part, though, I'd pick one or the other - Windows service or IIS.
you could have a windows service host the WCF and expose all end points on it..Http,TCP..
Windows service is better than IIS because IIS is a process in itself and then we place upon it a VD to host our website/WCF.As for the Windows Service,it will be one dedicated thread catering only to the WCF.I am sharing the app.config of windows service (details changed) to show how we have hosted WCF...hope it helps..
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.diagnostics>
<sources>
<source name="System.ServiceModel"
switchValue="Off" propagateActivity="true" >
<listeners>
<add name="SERVICE_MONITOR" type="System.Diagnostics.XmlWriterTraceListener"
initializeData="MyApp_MONITOR.svclog" />
</listeners>
</source>
<source name="MyApp_TRACE" switchValue="All" >
<listeners>
<add name="MyApp_TRACE_LISTENER" type="System.Diagnostics.XmlWriterTraceListener"
initializeData="MyApp_TRACE.svclog" />
</listeners>
</source>
</sources>
<trace autoflush="true" />
</system.diagnostics>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="OverAllServiceBehavior">
<serviceSecurityAudit
auditLogLocation="Application"
serviceAuthorizationAuditLevel="Failure"
messageAuthenticationAuditLevel="Failure"
suppressAuditFailure="true" />
<serviceDebug includeExceptionDetailInFaults="True" />
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
<serviceThrottling maxConcurrentCalls="10000" maxConcurrentSessions="10000"
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceCredentials>
<userNameAuthentication
userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType="MyAppHost.Authenticate, MyAppHost"/>
<serviceCertificate findValue="MyApp_MESSAGE" storeLocation="LocalMachine"
storeName="My" x509FindType="FindBySubjectName" />
<clientCertificate>
<authentication
certificateValidationMode="PeerTrust"
trustedStoreLocation="LocalMachine" />
</clientCertificate>
</serviceCredentials>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="OverAllEndPointBehavior" />
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="ServiceBasicHttpEndPointBinding" closeTimeout="00:00:59"
openTimeout="00:00:59"
messageEncoding="Text"
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="Message">
<message clientCredentialType="Certificate"/>
</security>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="ServiceWSHttpEndPointBinding" closeTimeout="00:00:59"
openTimeout="00:00:59"
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" />
<message clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
<netTcpBinding>
<binding name="ServiceTCPEndPointBinding" maxBufferSize="2147483647"
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxNameTableCharCount="2147483647" />
<security mode="TransportWithMessageCredential">
<transport
clientCredentialType="Certificate"
protectionLevel="EncryptAndSign" />
<message clientCredentialType="UserName" algorithmSuite="TripleDes"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="OverAllServiceBehavior"
name="MiddleWare.ServiceClasses.ServiceClass">
<host>
<baseAddresses>
<add baseAddress="net.tcp://127.0.0.1:15010/ServiceTCPEndPointMEX"/>
<add baseAddress="http://127.0.0.1:15020/ServiceHttpEndPointMEX"/>
<add baseAddress="https://127.0.0.1:15030/ServiceWSHttpEndPointMEX"/>
</baseAddresses>
</host>
<endpoint address="net.tcp://127.0.0.1:15040/ServiceTCPEndPoint"
contract="MiddleWare.ServiceContracts.IServiceContract" />
<endpoint address="http://127.0.0.1:15050/ServiceBasicHttpEndPoint"
contract="MiddleWare.ServiceContracts.IServiceContract"/>
<endpoint address="https://127.0.0.1:15060/ServiceWSHttpEndPoint"
contract="MiddleWare.ServiceContracts.IServiceContract"/>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
<appSettings>
<add key="UserName" value="USER"/>
<add key="Password" value="PASSWORD"/>
</appSettings>
</configuration>

Resources