WCF hosted in IIS - configuration trouble - silverlight

I made a WCF REST service and Silverlight client. Communication (based on XML) on Localhost (Development server) works fine, but not on IIS 7.5 (Windows Server 2008 R2). WCF service is successfully hosted on IIS, but when the client sends a request for service, the service returns Status: Aborted (wtf? - not html classic status like 404,200, but Aborted). The Silverlight client throws System.Net.WebException: The remote server returned an error: NotFound. BUT, if I send two request in quick succession, the first returns Aborted, the second WORKS! Then Silverlight falls. I do not understand it... Thank you in advance for your answer!
WCF Web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="RESTapi_test.RestServiceImpl" behaviorConfiguration="ServiceBehavior">
<endpoint address="" binding="webHttpBinding" contract="RESTapi_test.IRestServiceImpl"
behaviorConfiguration="web" >
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>

Enable Tracing on your service and inspect the trace files to know the reason why your first request fails and not the second one. Also make sure about the configuration of the service on IIS.

Related

Accessing WCF hosted in Windows Service in a silverlight application

I have hosted my Wcf services in a windows services, i am able to use it without any issue in my test console application, but when i try using the same service by using service reference in my silverlight application, it is giving me error.
ServiceReferences.ClientConfig has this entry:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
...
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:8732/myservices/myservice/"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_myservice"
contract="ServiceReference1.myservice" name="NetTcpBinding_myservice">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
I am getting this error:
Unrecognized element 'netTcpBinding' in service reference configuration. Note that only a subset of the Windows Communication Foundation configuration functionality is available in Silverlight.
Will appreciate your help..
Alpee
Have you Installed WCF Non-HTTP Activation on your IIS?
Found this rather good article on using NetTcpBinding with WCF and Silverlight: http://www.codeproject.com/Articles/311250/NetTcpBinding-Configurations-for-WCF-and-Silverlig
The other thing I noted is that apparently you can't specify security options with Silverlight and netTcp, so have to specify an insecure binding (from that same example):
<bindings>
<netTcpBinding>
<binding name="InsecureTcp" receiveTimeout="Infinite">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>

WCF - endpoint not found - error in corporate network

We've deployed a WPF application (.NET 4) to a corporate network. The application doesn't have direct access to the database. The application talks to the database using a WCF service. When the customer tries to login to the application he gets an error
There was no endpoint listening at
http://oururl/dataportal/wcfportal.svc that could accept the message.
This is often caused by an incorrect address or SOAP action. See inner
exception, if present, for more details.
But if the customer tries to login while Fiddler is running in the background, then it all works fine. See the app.config file below. Any help to diagnose the issue will be appreciated.
<configuration>
<system.serviceModel>
<!-- ZIP Enabled Dataportal -->
<extensions>
<bindingElementExtensions>
<add name="gzipMessageEncoding"
type="Microsoft.ServiceModel.Samples.GZipMessageEncodingElement, GZipEncoder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bindingElementExtensions>
</extensions>
<client>
<endpoint name="WcfDataPortal"
address="http://oururl/dataportal/wcfportal.svc"
binding="customBinding"
bindingConfiguration="dataportalCompressed"
contract="Csla.Server.Hosts.IWcfPortal" />
<metadata>
<policyImporters>
<extension type="Microsoft.ServiceModel.Samples.GZipMessageEncodingBindingElementImporter, GZipEncoder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</policyImporters>
</metadata>
</client>
<bindings>
<customBinding>
<binding name="dataportalCompressed">
<gzipMessageEncoding innerMessageEncoding="textMessageEncoding"/>
<httpTransport hostNameComparisonMode="StrongWildcard"
manualAddressing="False" maxReceivedMessageSize="6553600"
authenticationScheme="Anonymous" bypassProxyOnLocal="False"
realm="" useDefaultWebProxy="True" />
</binding>
</customBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="SSL_ServiceBehavior">
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
First check that are you able to access the SVC file from browser. There may be proxy issue.

Design WCF service to push data parameters with a byte array?

I have designed the WCF service with operation contracts that can store data in a SQL server database. The operation contract takes parameters such as dataID, dataDescrip., dataType and (byte array) data content. The byte array is originally a file that has to be stored in the database.
I used the WCF service within a web form client application (where the WCF service is referenced) to send the data, but when I send the file >40 kb as a byte array with other parameters it returns bad request 400 error. When I send files less than 30KB or so, the data is successfully stored in DB, no error is returned.
I believe this has to do with large data streaming and changing the size to larger numbers in web.config. I have tried to change the size in the client application web config, but no luck. Also changing the encoding tag to MTOM that returns mismatch client and service binding. I'm using wsHttpBinding.
Not sure what the problem is.
I have read: http://msdn.microsoft.com/en-us/library/ms733742.aspx
but how can I change my current wcf service to enable that while still storing the data to database?
My server config file, App.config from service library is:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="IncidentServiceLibrary.IncDataService">
<endpoint address="" binding="wsHttpBinding" contract="IncidentServiceLibrary.IIncDataService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/IncidentServiceLibrary/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- 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="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<connectionStrings>
.....
</connectionStrings>
</configuration>
The client config file, Web.config in the client I call my service from:
...
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IIncDataService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2000000" maxNameTableCharCount="2000000" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8732/Design_Time_Addresses/IncidentServiceLibrary/Service1/" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IIncDataService" contract="IncServiceReference1.IIncDataService" name="WSHttpBinding_IIncDataService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" /></system.serviceModel>
</configuration>

Silverlight 4 WCF Duplex Service - How to configure for HTTPS

How do I configure my Silverlight app and duplex WFC service to use HTTPS? Currently evrything works if using HTTP, but as soon as the client hits the site using HTTPS, the callback creation within the service fails. I believe I need to modify my config file, but I can't figure out what it should be set to.
Here is my current config:
<system.serviceModel>
<extensions>
<bindingExtensions>
<add name="pollingDuplex" type="System.ServiceModel.Configuration.PollingDuplexHttpBindingCollectionElement,
System.ServiceModel.PollingDuplex,
Version=4.0.0.0,
Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
</bindingExtensions>
</extensions>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentSessions="2147483647" maxConcurrentInstances="2147483647" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<pollingDuplex>
<binding name="myPollingDuplex" duplexMode="SingleMessagePerPoll" />
</pollingDuplex>
</bindings>
<services>
<service name="UnityEca.Web.Services.SearchPollingService">
<endpoint address="" binding="pollingDuplex" bindingConfiguration="myPollingDuplex" contract="UnityEca.Web.Services.SearchPollingService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
From my Silverlight app, I create the client proxy like so:
SearchPollingServiceClient client = new SearchPollingProxy.SearchPollingServiceClient(
new PollingDuplexHttpBinding { DuplexMode = PollingDuplexMode.SingleMessagePerPoll },
new EndpointAddress("../Services/SearchPollingService.svc"));
Thanks...
Have you implemented a clientaccesspolicy file for SSL? See here: http://timheuer.com/blog/archive/2008/10/14/calling-secure-services-with-silverlight-2-ssl-https.aspx
You may also need to add a security element to your ServicesReferences.clientconfig file:
<bindings>
<pollingDuplex>
<binding name="myPollingDuplex" duplexMode="SingleMessagePerPoll">
<security mode="Transport" />
</binding>
</pollingDuplex>
</bindings>
See this question for more details.

Hosting WCF service on IIS

I am trying to host a WCF service using IIS, (works fine in Cassini). However when I host it in IIS I get the following error:
"A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.)"
I thought this might be due to IIS and windows authentication, so I changed the connectionstring to directly login to the database with a uid and password, makes no difference. I don't think I am getting that far, as I would expect a sql security error if that were the case.
I have set up a brand new server (2008), and still I get the same issues...
What setting to I need to implement to get this going?
Example WCF Code
private GenericDataClassesDataContext _db = new GenericDataClassesDataContext();
public ReferenceValue[] GetReferenceValues()
{
try
{
return _db.ReferenceValues.ToArray();
}
catch (Exception e)
{
throw new FaultException(e.Message);
}
}
Web.Config
<?xml version="1.0"?>
<configuration>
<appSettings/>
<connectionStrings>
<!--<add name="TtasConnectionString" connectionString="Data Source=stdev07;Initial Catalog=Ttas;;uid=srvTtas;pwd=pa$$w0rd;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>-->
<add name="TTASConnectionString" connectionString="Data Source=STDEV07;Initial Catalog=IRF;Integrated Security=SSPI" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0">
</compilation>
<authentication mode="Windows"/>
<identity impersonate="true"/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/></system.web>
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="silverlightFaults" type="Moe.Tactical.GenericData.Wcf.SilverlightFaultBehavior, Moe.Tactical.GenericData.Wcf, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<behaviors>
<endpointBehaviors>
<behavior name="SilverlightFaultBehavior">
<silverlightFaults />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Moe.Tactical.GenericData.Wcf.GenericDataServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<!--<serviceDebug includeExceptionDetailInFaults="false" />-->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="winAuthBasicHttpBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="Moe.Tactical.GenericData.Wcf.GenericDataServiceBehavior" name="Moe.Tactical.GenericData.Wcf.GenericDataService">
<!--bindingConfiguration="winAuthBasicHttpBinding" [in gap]-->
<endpoint address=""
binding="basicHttpBinding"
behaviorConfiguration="SilverlightFaultBehavior"
contract="Moe.Tactical.GenericData.Wcf.IGenericDataService">
<identity>
<dns value="localhost:3637"/>
</identity>
</endpoint>
<!--<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>-->
</service>
</services>
</system.serviceModel>
</configuration>
I think the reason is in the following line of web.config:
<identity impersonate="true"/>
You should change it to
<identity impersonate="false"/>

Resources