调用Web服务错误“远程服务器返回了意外响应:(502)连接被拒绝。”

时间:2016-09-18 06:23:57

标签: web-services

逗人, 我有来自客户的以下Web服务来致电: here

当我尝试使用它时,我收到了这个错误:     远程服务器返回意外响应:(502)连接被拒绝。

内部异常是:{“远程服务器返回错误:(502)Bad Gateway。”}

这是我的代码:

AuthenticateService.AuthenticatePortClient oAuthenticatePortClient = new AuthenticateService.AuthenticatePortClient();
AuthenticateService.authenticateRequest oauthenticateRequest = new AuthenticateService.authenticateRequest();

oauthenticateRequest.serviceId = "MobileTeam";
oauthenticateRequest.serviceKey = "AJEC1";
oauthenticateRequest.userName = "MMelhem";
oauthenticateRequest.password = "P@$$w0rd";

AuthenticateService.authenticateResponse oregisterUserResponse = oAuthenticatePortClient.authenticate(oauthenticateRequest);

并且web.config是:

<configuration>
<system.net>
<defaultProxy>
<proxy usesystemdefault="False" bypassonlocal="False" />
</defaultProxy>
</system.net>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>

<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="AuthenticatePortSoap11" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://172.16.0.82:80/Ajec_sso_api/authenticate"
binding="basicHttpBinding" bindingConfiguration="AuthenticatePortSoap11"
contract="AuthenticateService.AuthenticatePort"    name="AuthenticatePortSoap11" />
</client>
</system.serviceModel>
</configuration>

2 个答案:

答案 0 :(得分:0)

您使用什么工具生成客户端代码(或手工编码)?

我使用了wsimport,但代码与你的代码略有不同。由于IP似乎在本地域(172.16.0.82),我无法测试它。如果您有兴趣,可以尝试一下。

我使用wsimport生成/编译客户端类文件:

wsimport -keep http://ajec.proxym-it.net/Ajec_sso_api/authenticate.wsdl

然后像这样对客户进行编码:

import com.ajec_sso.authenticate.*;    
public class TClient {
    static AuthenticatePortService service = new AuthenticatePortService();
    public static void main(String[] args) {    
       try {
            AuthenticatePort port = service.getAuthenticatePortSoap11();    
            AuthenticateRequest req = new AuthenticateRequest();
            AuthenticateResponse res = new AuthenticateResponse();    
            req.setServiceId("MobileTeam");
            req.setServiceKey("AJEC1");
            req.setUserName("MMelhem");
            req.setPassword("P@$$w0rd");    
            res = port.authenticate(req);
       } catch(Exception e) {
            e.printStackTrace();
       }
   }
}

像这样编译(生成的com目录在当前目录中)。

javac TClient.java

答案 1 :(得分:0)

我通过替换端点地址解决了这个问题     http://172.16.0.82:80/Ajec_sso_api/authenticate 至     http://ajec.proxym-it.net/Ajec_sso_api/authenticate