开发者

.NET and webservices: how?

开发者 https://www.devze.com 2022-12-11 23:12 出处:网络
Im trying to make a webservice in ASP.NET and get the data in a Smart Device Application. I have the standard HelloWorld webservice and i wanna get the data in my application, but when i try to add

Im trying to make a webservice in ASP.NET and get the data in a Smart Device Application.

I have the standard HelloWorld webservice and i wanna get the data in my application, but when i try to add a web reference to my project, Visual Studio can't find any webservices running. If i start the WebService in the WebService project and copy/paste the url to the "Add WebReference" in the Application project, Visual Studio finds the Webservice and i can use the InttilSence to find the HelloWorld Method (WebServiceClass.HelloWorld()) in the WebService. But when i the开发者_高级运维n run the Application project the complier gives an error saying that it can't connect to the WebService.

How do i do this? How do i access a webservice in an Application project? Every tutorial or book i have read about the subject doesn't tell anything about how the webservice should i run. In my world the webservice project should be running before i can access it from another project or am i wrong?


Consider reading Rick Strahl's Creating Web Services with .NET and Visual Studio.

From there, you'll get the basics. You can build and deploy your XML SOAP web service.

Then you'll need to have your application use that web service as a 'Web Reference'. Start by "Add Web Reference".

.NET and webservices: how?


(source: usaepay.com)


First, you should publish the web service to some server (even your own local IIS) rather than using the Visual Studio web server.

Then in your application, point to the correct URL wherever you published it when adding the reference.


While this is a bit low-tech, couldn't you create a web requrest from the Smart Device Application to hit the webservice directly? That would be my suggestion.

An example would be using the "WebRequest" Class.


It sounds like when you try to access the Web Service from your app, the service is not running (possibly because you're only running it in the Cassini server?).

The fact that you were able to generate the Web Reference means that at some point, the service was running and was able to generate the helper classes by examining the service.

I would do as David Stratton suggests and publish it somewhere where it can run while you are developing the Smart Device app (like your local IIS).

You might also take the opportunity to wrap the service call with some error handling - maybe catch the specific exception being thrown (System.Net.WebException?)

0

精彩评论

暂无评论...
验证码 换一张
取 消