简体   繁体   中英

Calling a web service from a .net windows application

I need to call a web service from a .net web application, here is my code:

LoginRequest req = new LoginRequest();
LoginRequestBody reqBody = new LoginRequestBody();

reqBody.username = txtUsername.Text;
reqBody.password = txtPassword.Text;

req.Body = reqBody;

LoginResponse resp = new LoginResponse();
LoginResponseBody respBody = new LoginResponseBody();

resp.Body = respBody;
MessageBox.Show(respBody.LoginResult.ToString());

The message returned is always false, while the message from the web service (when I test directly) is returning true, what's wrong with my code?

You are not actually calling the web-service! You should not be creating a response directly - you should be asking the web-service for one, eg

LoginResponse response = LoginService.Login(req);

However, I don't know what your service is actually called, so the above is just a sample.

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