简体   繁体   中英

Calling WebService In Cross Domain

I want to call webservice from domain A with the C# code in Domain B. I have tried to add web reference with URL of that web service but it gives error like

There was an error downloading 'http://localhost:15666/MailBox/'.
Unable to connect to the remote server
No connection could be made because the target machine actively refused it 127.0.0.1:15666
There was an error downloading 'http://localhost:15666/MailBox/$metadata'.
Unable to connect to the 

I am having so many issues because of cross domains. Is there any solution for this?

Since you have requested the web service on localhost, this isn't a cross-domain issue. I suspect that you need to update your reference to point to a web service on a different machine.

Your problem (at least the exception you pasted) has nothing to do with calling web services on another domain. It indicates that your machine (localhost) has port 15666 closed and hence you receive the actively refused it error message. You are either not running your web service on that port or your windows firewall is blocking the connection, although this is very unlikely since firewalls usually accept connections from localhost.

You can always check this sort of thing by telneting to localhost on the particular port you are interested in or by using nmap to scan your own ports.

嗨,最后我得到了我的问题的答案,这不是跨域问题,但是我遇到了问题,因为我没有为Web服务创建迪斯科文件或WSDL文件,所以我得到了元数据错误。我在本地运行Web服务,从那里获取WSDL文件并为我的网络服务和繁荣创建新的WSDL文件...问题已解决。感谢您的所有帮助...

You have to create a file (clientaccesspolicy.xml) and put it into the wwwroot directory or the main directory of your webservice.

Content of the file should be like:

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

You can read more about that at To use a clientaccesspolicy.xml file to allow cross-domain access

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM