简体   繁体   English

呼叫网络服务:我在这里做错了什么?

[英]Calling a web service: what am I doing wrong here?

I have the following code for consuming a service that is not working for me. 我有以下代码用于使用对我不起作用的服务。 Can anyone suggest what I can do to narrow down whats going wrong? 谁能建议我可以做些什么来缩小问题所在? I know this is vague so please tell me what you require to provide any suggestions. 我知道这很模糊,所以请告诉我您需要提供什么建议。

The address is: http://localhost:57667/ExampleService.svc/ 地址为: http:// localhost:57667 / ExampleService.svc /

When visiting directly I get the 'You have created a service... message' 直接访问时,我会收到“您已创建服务...消息”

The code that goes wrong is here. 出错的代码在这里。 It causes the following error: 它导致以下错误:

_url = "http://localhost:57667/ExampleService.svc";
TextReader textReader = new StringReader(HttpPostClient.Post(new Uri(_url), bodyData.ToString(), _exampleServiceRequestEncoding,     Properties.Settings.Default.HttpPostClientExampleAvailabilityTimeout));

ERROR MESSAGE: When visiting this URL directly: http://localhost:57667/ExampleService.svc/ProcessRequest 错误消息:直接访问此URL时: http:// localhost:57667 / ExampleService.svc / ProcessRequest

The exception message is 'No component for key example.ExternalWebServiceStubs.Example.ExampleService was found'. 
Castle.MicroKernel.DefaultKernel.get_Item(String key) at Castle.Facilities.WcfIntegration.WindsorInstanceProvider.GetInstance

many thanks, 非常感谢,

The normal practice would be to create a proxy class via svcutil.exe (visual studio command prompt) or "add service reference" to consume the service, and then for you to use the methods of your proxy class to call your service's methods. 通常的做法是通过svcutil.exe(Visual Studio命令提示符)或“添加服务引用”创建代理类以使用该服务,然后让您使用代理类的方法来调用服务的方法。

This tutorial should help (it's based on Visual Studio 2005, you didn't say what version you were using, but you should get a good grounding) 本教程应该有所帮助(它基于Visual Studio 2005,您没有说出使用的是哪个版本,但是应该有很好的基础)

http://msdn.microsoft.com/en-us/library/bb332338.aspx#msdnwcfhc_topic6 http://msdn.microsoft.com/zh-CN/library/bb332338.aspx#msdnwcfhc_topic6

Since troubleshooting wcf services will be lot more easier when you provide web.config element also at service side. 由于在服务端也提供web.config元素时,对wcf服务进行故障排除将变得更加容易。

My general guess here is, all the wcf services by default uses wsHttpBinding which will not allow direct calling of service like an asmx service we do. 我的一般猜测是,默认情况下,所有wcf服务都使用wsHttpBinding,这将不允许像我们的asmx服务那样直接调用服务。

You can replace wsHttpBinding with basicHttpBinding and disable the security to your service in order to get the service work like you are expecting. 您可以使用basicHttpBinding替换wsHttpBinding并禁用服务的安全性,以使服务按预期运行。

Please add some more details about ExampleService.svc binding and it will help you get this resolved fast 请添加有关ExampleService.svc绑定的更多详细信息,它将帮助您快速解决此问题

Hope this will help 希望这会有所帮助

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

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