从 Silverlight 4 客户端访问 SOAP Web 服务
我正在进行概念验证,从 Silverlight 4 客户端应用程序访问公共 Web 服务。当我尝试调用此示例公共 Web 服务时,出现以下错误:
An error occurred while trying to make a request to URI 'http://www.w3schools.com/webservices/tempconvert.asmx'.
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.
我只能访问具有这些策略的 Web 服务吗?还是我根本没有在项目中正确配置 ASMX 服务?调用服务的代码如下:
// Create
var webServiceProxy = new TempConvert.TempConvertSoapClient();
// Delegate
webServiceProxy.FahrenheitToCelsiusCompleted += (s, args) =>
{
// Fail?
if (args.Error != null)
{
// Message
MessageBox.Show(string.Format("Something went wrong!\n\n{0}", args.Error.Message));
}
else
{
// Message
MessageBox.Show(string.Format("50 f to c is {0}.", args.Result));
}
};
// Call
webServiceProxy.FahrenheitToCelsiusAsync("50");
I am doing a proof of concept where I access a public web service from my Silverlight 4 client application. When I attempt to make the call this sample public web service, I get the following error:
An error occurred while trying to make a request to URI 'http://www.w3schools.com/webservices/tempconvert.asmx'.
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.
Can I only access web services which have these policies in place or am I simply not configuring my ASMX service correctly in my project? The code to call the service is as follows:
// Create
var webServiceProxy = new TempConvert.TempConvertSoapClient();
// Delegate
webServiceProxy.FahrenheitToCelsiusCompleted += (s, args) =>
{
// Fail?
if (args.Error != null)
{
// Message
MessageBox.Show(string.Format("Something went wrong!\n\n{0}", args.Error.Message));
}
else
{
// Message
MessageBox.Show(string.Format("50 f to c is {0}.", args.Result));
}
};
// Call
webServiceProxy.FahrenheitToCelsiusAsync("50");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您从计算机上运行此程序,则很可能会跨越域边界,并要求被调用站点制定从不同域进行调用的策略。
Microsoft 有大量相关信息,查找“silverlight跨域”以获取更多信息。
Most likely if you're running this from your machine, you're crossing domain boundaries and require the called site to have the policies in place to call from a different domain.
Microsoft has plenty of information about it, also look up 'silverlight cross domain' for more information.
当服务器收到 url= /clientaccesspolicy.xml 的 GET 时
确保它的答案是:
when server received the GET with url= /clientaccesspolicy.xml
make sure it answers with: