none
problem Accessing wcf service methods after hosting in iis7

    Question

  • hi..

    i have ceated a wcf service application and i hosted the wcf service.

    now i have added the service reference in to my local application.

    during run time i clicked button to access my service methods i received the below error

    "An error occurred while trying to make a request to URI 'http://example.sample.com/wcfservice/Service1.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."


    but i have added croosdomain and client access policy xml files in my hosted wcf service.
    the two file details are below

    crossdomain.xml


    <?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>


    clientaccesspolicy.xml
    <?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>


    so what i was missed.. and why i am getting the above error..

    need ur suggestions..

    regards
    gopal.s

    Wednesday, May 16, 2012 3:22 AM

Answers

  • Hi,

    The clientaccesspolicy.xml file will help only if you are using the HTTP protocol.

    If you want to use TCP protocol such as NET.TCP then you need to do one more thing. You will have to add an exception in the windows firewall on th server side for port 4502 or some other port.

    The clientaccesspolicy.xml will look like the following(You need to place this in C:\inetpub\wwwroot or C:\inetpub\vhosts\default\htdocs directory on the server):

    <?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"/>
            <socket-resource port="4502" protocol="tcp"/>
          </grant-to>
        </policy>
      </cross-domain-access>
    </access-policy>

    Update:

    Also, in either case there is no need for creating a interface 'ICrossDomainService', implement it, read the clientaccesspolicy.xml file using FileStream. You just have to place the file in the directory that I have mentioned above and it should work. It worked for me and should work for everyone else.

    For more information check this:

    http://forums.silverlight.net/p/254512.aspx/1?Need+help+with+Silverlight+5+and+WCF+net+tcp+binding

    Here is my working Silverlight 5 application using NET.TCP binding:

    http://iconnect.arshdeep-virdi.com/web/

    Thanks,

    Arshdeep

    Tuesday, May 22, 2012 10:51 PM

All replies

  • Hi,

    This may be help you.

    At First you will create a xml file like clientaccesspolicy.xml

    and copy and past the code below

    <?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>
    and then you will create a interface like ICrossDomainService and copy and paste the code below
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    using System.ServiceModel.Channels;
    using System.ServiceModel.Web;


    namespace Sample
    {
    [ServiceContract]
    public interface ICrossDomainService
    {
    [OperationContract]
    [WebGet(UriTemplate = "clientaccesspolicy.xml")]
    Message ProvidePolicyFile();
    }
    }
    
    
    when you create a wcf class library then you will see the interface class and implementation 
    in the implementation class you will inherite like
        public class MessageService : IMessageService, ICrossDomainService
    {
    public MessageService()
    {

    }

    public string GetMessage(string messageCode)
    {
    return 1;
    }

    public bool IsValidUserOperation(int pgID, int operationType, int location)
    {
    return true;
    }

    public System.ServiceModel.Channels.Message ProvidePolicyFile()
    {
    FileStream filestream = File.Open(@"clientacesspolicy.xml", FileMode.Open);
    XmlReader reader = XmlReader.Create(filestream);
    System.ServiceModel.Channels.Message result = Message.CreateMessage(MessageVersion.None, "", reader);
    return result;
    }
    }
    
    
    And Finally Build and host the wcf service to your IIS
    i hope that you will get data from silverlight by asyn...ly................
    
    
    Wednesday, May 16, 2012 5:07 AM
  • Hi,

    The clientaccesspolicy.xml file will help only if you are using the HTTP protocol.

    If you want to use TCP protocol such as NET.TCP then you need to do one more thing. You will have to add an exception in the windows firewall on th server side for port 4502 or some other port.

    The clientaccesspolicy.xml will look like the following(You need to place this in C:\inetpub\wwwroot or C:\inetpub\vhosts\default\htdocs directory on the server):

    <?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"/>
            <socket-resource port="4502" protocol="tcp"/>
          </grant-to>
        </policy>
      </cross-domain-access>
    </access-policy>

    Update:

    Also, in either case there is no need for creating a interface 'ICrossDomainService', implement it, read the clientaccesspolicy.xml file using FileStream. You just have to place the file in the directory that I have mentioned above and it should work. It worked for me and should work for everyone else.

    For more information check this:

    http://forums.silverlight.net/p/254512.aspx/1?Need+help+with+Silverlight+5+and+WCF+net+tcp+binding

    Here is my working Silverlight 5 application using NET.TCP binding:

    http://iconnect.arshdeep-virdi.com/web/

    Thanks,

    Arshdeep

    Tuesday, May 22, 2012 10:51 PM