Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从.net windows应用程序调用web服务_C#_.net_Web Services - Fatal编程技术网

C# 从.net windows应用程序调用web服务

C# 从.net windows应用程序调用web服务,c#,.net,web-services,C#,.net,Web Services,我需要从.net web应用程序调用web服务,以下是我的代码: LoginRequest req = new LoginRequest(); LoginRequestBody reqBody = new LoginRequestBody(); reqBody.username = txtUsername.Text; reqBody.password = txtPassword.Text; req.Body = reqBody; LoginResponse resp = new Login

我需要从.net web应用程序调用web服务,以下是我的代码:

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());

返回的消息总是false,而来自web服务的消息(当我直接测试时)返回true,我的代码有什么问题吗?

您实际上并没有调用web服务!您不应该直接创建响应—您应该向web服务请求响应,例如

LoginResponse response = LoginService.Login(req);

但是,我不知道您的服务实际上被调用了什么,所以上面只是一个示例。

您实际上并没有调用web服务!您不应该直接创建响应—您应该向web服务请求响应,例如

LoginResponse response = LoginService.Login(req);

但是,我不知道您的服务实际被调用了什么,所以上面只是一个示例。

LoginResponse或
LoginResponseBody
的构造函数做了什么?如果你猜他们没有,那么你的问题是你从来没有调用过web服务做
LoginResponse
LoginResponseBody
的构造函数做什么?如果你猜他们没有,那么你的问题是你从不调用web服务我的web服务称为OAAuthentication,但在它里面只有loginrequest、loginrequestBody、loginresponse、loginresponseBody、Service1Soap,web服务中的Service1SoapChannel和Service1SoapClient方法称为Loginmy web服务称为OAAuthentication,但其中只有loginrequest、loginrequestBody、loginresponse、loginresponseBody、Service1Soap、Service1SoapChannel和Service1SoapClient方法称为Login