calling https wcf service from silverlight - wcf

i am trying to access a https wcf service from silverlight.
the clientaccesspolicy is placed on service root and i have validated through silverlightspy its showing it as valid and calls allowed.
i am able to call that webservice successfully from desktop client but when tries to call from silverlight it throws an error that call to .... service failed may be cross domain poliecy etc is not valid....
any ideas????
here is the service cross domain policy too:
<?xml version="1.0" encoding="utf-8"?>
<access-policy> <cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<domain uri="*" />
</allow-from>
<grant-to>
<resource include-subpaths="true" path="/" />
</grant-to>
</policy>
</cross-domain-access>
</access-policy>

You need a separate domain node for https:
<domain uri="https://*" />
From this post:
http://timheuer.com/blog/archive/2008/10/14/calling-secure-services-with-silverlight-2-ssl-https.aspx

This is a great source of silverlight + wcf info:
http://www.netfxharmonics.com/2008/11/Understanding-WCF-Services-in-Silverlight-2

If the service and the silverlight app are served from the same web site and you are using Silverlight 4, you can accomplish this without a cross domain policy file by:
Accessing the silverlight application through https
Using a relative address in the ServiceReferences.ClientConfig file to access the service
Using transport mode security in the BasicHttpBinding for the service.
Here's an example of the ServiceReferences.ClientConfig:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMyService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<!--Transport mode security (setup the same way on the server):-->
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<!--Relative address (This is the part that requires SL4):-->
<endpoint address="../Services/MyService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMyService"
contract="MyApplication.MyService" name="BasicHttpBinding_IMyService" />
</client>
</system.serviceModel>
</configuration>

Have you looked here?
Calling WCF Service from Silverlight

Related

WCF calling a external service - communication faulted state

I´m building a winform client using VS 2013. I want to consume a 3party java secure and external (using https with certificate) web service.
I have access to the wsdl. I added a service reference to my .net project referencing the address of the Endpoint and I configured my web.config with wsHttpBinding and transport. ( I have also tried with basicHttpBinding )
In code, I create a client service object and I can see its methods and data types normally.
I have seen that as soon as I create the object, the InnerChannel property is in faulted state mode and I do not understand why.
Show my code in debug mode
The problem is that when calling any of the service object methods, It gives the error:
An unhandled exception of type 'System.InvalidOperationException'
occurred in System.Xml.dll
'System.ServiceModel.CommunicationObjectFaultedException' occurred in
System.ServiceModel.dll
Additional information: The communication object,
System.ServiceModel.ChannelFactory`1
[myproyect.SR.NotificaWsPortType], can not be used for communication
because it is in the Faulted state.
Additional information: There was an error reflecting 'return'.
Can anybody help me?
web.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="NotificaWsBinding">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://<address here>"
binding="wsHttpBinding" bindingConfiguration="NotificaWsBinding"
contract="SR.NotificaWsPortType" name="NotificaWsPort" />
</client>
</system.serviceModel>
</configuration>
I finally found the answer. There was a problem mapping the webservice in .NET because the webservice was developed in java and had a problem whit microsoft technology.
So I spoke with the service providers and they did not have any problems with java but with .net. They changed something in their internals and it worked for me.

Simple WCF service not getting called after deploying on different machine, however works fine on my local system

I just tried to create a very simple wcf application. That is on a click of button i am trying to print "Hello World" on the page. I published the service and as again it works fine on my local system, but same when i try to deploy on server it doesn't. This application is damn simple, no complexities, not database connection, nothing. But still fails to call the service from the server. Checking on services,(Service1.svc -. Right Click -> Browse) works fine, but then why it fails to call through application, i don't know. Its getting rather more confusing now. Totally clueless on this. Posting all 3 necessary files used in the code.
web.config file :
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name ="ApplicationReturnString.Web.Service1.svc">
<endpoint address="" binding="basicHttpBinding"
contract="ServiceReference1.IService1"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
</configuration>
ClientAccessPolicy.xml file:
<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource include-subpaths="true" path="/"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
CrossDomain.xml file:
<?xml version="1.0" ?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>
ServiceRefrence.ClientConfig file :
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:52731/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
Thanks Roy & Nitin. Actually the issue was on setting up endpoint address in web.config file and also as the services was getting deployed in other machine, the URL of the application was getting changed. So i made some important changes given below: 1. Gave the endpoint address, endpoint name and Contract details in web.config file same as in ServiceRefrence.ClientConfig file. 2. Change the endpoint address in ServiceRefrence.ClientConfig without specific port details:; rather then ;and 3. Coded in the app to get the URI address of the machine where it executes so that wherever the app is deployed user has not to worry about the localhost address and its port details: Uri servUri = new Uri("../Service.svc", UriKind.Relative); EndpointAddress servAddr = new EndpointAddress(servUri); ServiceReferenceForSelect.ServiceForSelectClient objSelect = new ServiceForSelectClient("BasicHttpBinding_IService", servAddr);

WCF service on IIS hosted cant be connected with test web app on same server but from localhost can

I have a WCF service which I hosted on IIS 7.5 on my web server and I build a simple web application to test my wcf service. I can connect and send request and get response when I run my test client on my localhost IIS express. my endpoint address is webserver address where my wcf is hosted but when I publish my test web app on the same server and try to do tests, I get no request and no response. nothing happens. test application doesnt have anything beside a button and a textbox. no javascript etc. I tried making it as a virtual app and standalone but no chance. what could be the problem?
here is how my webconfig looks like
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" requestValidationMode="2.0" maxRequestLength ="8192" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="serviceBasicHttpBinding" receiveTimeout="00:10:00"
sendTimeout="00:10:00" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://myservice.com/Service.svc"
binding="basicHttpBinding" bindingConfiguration="serviceBasicHttpBinding"
contract="serviceWCF.IService" name="serviceBasicHttpEndpoint" />
</client>
</system.serviceModel>
thanks for your help.

WCF: Using nettcp in an Silverlight 4.0 application with HTTPS

I have a Silverlight 4.0 application using nettcp working in HTTP. I then attempted to switch from http to https. This is where I started to run into issues. When I run the application I receive an Internet Explorer notification "Display Mixed Content?". If I click "Yes" then I receive an error in my application:
Could not connect to net.tcp://ServerName:4502/TestService.svc/netTcp. The connection attempt lasted for a time span of 00:00:01.2191219. TCP error code 10013: An attempt was made to access a socket in a way forbidden by its access permissions.. This could be due to attempting to access a service in a cross-domain way while the service is not configured for cross-domain access. You may need to contact the owner of the service to expose a sockets cross-domain policy over HTTP and host the service in the allowed sockets port range 4502-4534.
My ClientConfig is as follows:
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="NetTcpBinding_ITestService">
<binaryMessageEncoding />
<tcpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="net.tcp://ServerName:4502/TestService.svc/netTcp"
binding="customBinding" bindingConfiguration="NetTcpBinding_ITestService"
contract="TestServer.ITestService" name="NetTcpBinding_ITestService"/>
</client>
</system.serviceModel>
</configuration>
My Web.config is as follows:
<netTcpBinding>
<binding name="netTcpBindingConfig">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="TestService">
<endpoint address="netTcp" binding="netTcpBinding" bindingConfiguration="netTcpBindingConfig" contract="ITestService" />
<endpoint address="mex" binding="mexHttpsBinding" name="mex" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://ServerName:4502/TestService.svc" />
<add baseAddress="https://ServerName/TestService.svc" />
</baseAddresses>
</host>
</service>
</services>
At the Root of my server I have a file called clientaccesspolicy.xml:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="http://*"/>
<domain uri="https://*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true" />
<socket-resource port="4502-4530" protocol="tcp" />
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
The nettcp communication does not need to be secure, but other services in the application require security. Is it possible to get nettcp running in an HTTPS hosted application?

WCF / Csla Hell

I'm trying to build a proof of concept Csla 3.7/Silverlight 3 app and have been working my way through Rocky's tutorials. It's a really simple one form/one business object data editing app and everything is just peachy right up until the point where I try to get the Wcf configured so that the Silverlight app can talk to the Data Portal.
The error I'm getting is:
CommunicationException was unhandled by user code
An error occurred while trying to make a request to URI 'http://localhost:1406/WcfPortal.svc'.
This could be due to attempting to access a service in a cross-domain way without a proper cross-domain policy in place, or a policy that is unsuitable for SOAP services.
You may need to contact the owner of the service to publish a cross-domain policy file and to ensure it allows SOAP-related HTTP headers to be sent.
This error may also be caused by using internal types in the web service proxy without using the InternalsVisibleToAttribute attribute.
Please see the inner exception for more details.
I'm totally mystified by this as I'm a bit of a n00b to Silverlight & WCF. My setup is pretty straight forward for a Csla Silverlight app. I have 4 projects:
CslaSilverlight : Silverlight Project
CslaSilverlight.Client : Silverlight Class Library
CslaSilverlight.Server : .NET Class Library
CslaSilverlight.Web : ASPNET Project to host the SL app
Everything is running locally on my laptop under Cassini. I want the DataPortal to run outside of Silverlight so that I can access SQL Server. I think that the problem may be with my Wcf Config in the Silverlight application which is specified in a ServiceReferences.ClientConfig file:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IWcfPortal" maxBufferSize="65536"
maxReceivedMessageSize="65536" receiveTimeout="10" sendTimeout="10">
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:1406/WcfPortal.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWcfPortal"
contract="Csla.WcfPortal.IWcfPortal" name="BasicHttpBinding_IWcfPortal" />
</client>
</system.serviceModel>
</configuration>
I'm wondering if the port number important, when I change it I get a different error. I'm also wondering if the format of the endpoint address correct.
Not sure if it's important, but my serviceModel settings from the ASPNet web.config are:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="WcfPortalBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="WcfPortalBehavior" name="Csla.Server.Hosts.Silverlight.WcfPortal">
<endpoint address="" binding="basicHttpBinding" contract="Csla.Server.Hosts.Silverlight.IWcfPortal">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
If I am thinking it right, then the error may be telling you the entirely correct thing, you are missing a cross domain policy. The silverlight app is accessing the WCF service from a remote location and needs the authorisation to accept the request.
This occured for me in dev when the project was in three parts, the SL App, the WCF web service and the website. The web site and WCF service are run independantly, although they were a part of the same solution. As such Cassini is run twice and you are crossing a boundary.
I have a clientaccesspolicy.xml file along with the web service in development that has the following:
<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
The file is a allowing anyone and everything, you would refine it for production, but in dev it was the easiest way. Google wcf client access policy / wcf cross domain policy - it is a common issue.