简体   繁体   English

跨域调用WebService

[英]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 我想使用域B中的C#代码从域A调用网络服务。我试图添加带有该网络服务URL的网络引用,但是它给出了如下错误

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. 由于您已在localhost上请求了Web服务,因此这不是跨域问题。 I suspect that you need to update your reference to point to a web service on a different machine. 我怀疑您需要更新引用以指向另一台计算机上的Web服务。

Your problem (at least the exception you pasted) has nothing to do with calling web services on another domain. 您的问题(至少是您粘贴的异常)与在另一个域上调用Web服务无关。 It indicates that your machine (localhost) has port 15666 closed and hence you receive the actively refused it error message. 它表明您的计算机(本地主机)已关闭端口15666 ,因此您收到actively refused it错误消息。 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. 您要么不在该端口上运行Web服务,要么Windows防火墙阻止了该连接,尽管这种情况不太可能发生,因为防火墙通常接受来自本地主机的连接。

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. 您始终可以通过在您感兴趣的特定端口上远程登录到localhost或使用nmap扫描自己的端口来检查这种情况。

嗨,最后我得到了我的问题的答案,这不是跨域问题,但是我遇到了问题,因为我没有为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. 您必须创建一个文件(clientaccesspolicy.xml)并将其放入wwwservice的wwwroot目录或主目录中。

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 您可以在使用clientaccesspolicy.xml文件允许跨域访问中了解有关此内容的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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