0

I have a WCF Service that Hosted in Windows Service

It uses NetTCPBinding and i could connect, i want to implement new Silverlight client to access the service

i have walk through the normal way to add service reference, and it was added with Empty "ServiceReferences.ClientConfig"

so i have viewed some threads and topics, at last i have write my configuration manually for the service

when i try to connect it show's this exception Could not connect to net.tcp://localhost:4502/MyService/Service. The connection attempt lasted for a time span of 00:00:02.2111265. 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.

i believe that the problem related to ClientAccessPolicy.xml file

after search people say i need to have IIS7 installed and file is accessible through it, i have tried this but i couldn't make it work

but, i have worked on this before, but i was using PollinghttpBinding no NetTCP, and i have created another service contract to return the ClientAccessPolicy file

i have tried to do the same i do before with PollinghttpBinding but i can't write the right Configuration of the Service

My client refuse to use IIS, so could i use this way and what is the right configuration i should use with this service?

this is the configuration i use for my Service

<service behaviorConfiguration="serviceBehavior" name="MyService">
              <endpoint address="net.tcp://localhost:4502/MyService/Service"       behaviorConfiguration="endpointBehavior" binding="netTcpBinding"         bindingConfiguration="netTcpServiceBinding" contract="IMyService">
                  <identity>
                      <dns value="localhost"/>
                  </identity>
              </endpoint>
              <endpoint address="net.tcp://localhost:7000/MyService/mex"     binding="mexTcpBinding" contract="IMetadataExchange"/>
          </service>

can anyone give help?

mkalashy
  • 103
  • 1
  • 4

1 Answers1

0

Net.tcp bindings are not supported "out-of-the-box" in Silverlight. That's why the config is empty. But you can use it anyway, by using a customBinding and setting the properties you need. However, I have never tried this fyself.

If this is a cross domain problem, this is nedeed related to the ClientAccessPolicy.xml file. Normally (as stated many places on various forums), this is solved by putting the file in the root of the site. So if your service runs on "http://localhost/MyService", the file should be put so it's available in "http://lovalhost".

However, without a IIS available, this has to be done another way. You will have to create an endpoint on the root manually in the Windows Service, where this file is available. This is a normal BasicHttp binding either you use "net.tcp" or "http".

I have done this with success this way:

Policy interface:

using System;
using System.IO;
using System.ServiceModel;
using System.ServiceModel.Web;

namespace MyPolicyService
{
    [ServiceContract]
    public interface IPolicyRetriever
    {
        [OperationContract]
        Stream GetPolicy();
    }
}

Policy class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.ServiceModel.Web;

namespace MyPolicyService
{
    public class PolicyRetrieverBase : IPolicyRetriever
    {
        public Stream StringToStream(String result)
        {
            WebOperationContext.Current.OutgoingResponse.ContentType = "application/xml";
            return new MemoryStream(Encoding.UTF8.GetBytes(result));
        }

        public Stream GetSilverlightPolicy()
        {
            string result = @"<?xml version=""1.0"" encoding=""utf-8""?>
<access-policy>
    <cross-domain-access>
        <policy>
            <allow-from http-request-headers=""*"" http-methods=""*"">
                <domain uri=""*""/>
            </allow-from>
            <grant-to>
                <resource path=""/"" include-subpaths=""true""/>
            </grant-to>
        </policy>
    </cross-domain-access>
</access-policy>";

            return StringToStream(result);
        }

        public Stream GetFlashPolicy()
        {
            string result = @"<?xml version=""1.0"" encoding=""utf-8""?>
<!DOCTYPE cross-domain-policy SYSTEM ""http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"">
<cross-domain-policy>
    <site-control permitted-cross-domain-policies=""all""/>
    <allow-access-from domain=""*"" secure=""false"" />
    <allow-http-request-headers-from domain=""*"" headers=""*"" secure=""false"" />
</cross-domain-policy>";

            return StringToStream(result);
        }
    }
}

When these classes are created, create the service almost just as you would start the "net.tcp" service, but of course change it to BasicHttpBinding and use some different behaviors and property values related to the BasicHttpBinding (like TransferMode = Buffered etc).

This policy service should, needless to say, be started on the site root (http://localhost). ID YOU HAVE THE IIS running on this server, do NOT start this policy service because this will take over this address :-)

Hope that gets you moving in the correct-ish direction :-)

Mats Magnem
  • 1,375
  • 1
  • 10
  • 21