Tag Archives: webservice

JQuery remote calling WebService reported an error, 500 error

In these two days, CRM, one of the key development branches of the Department, went online. JQuery is used to call WebService through Ajax. An inexplicable 404 error was reported during the test. After analysis, 404 it is because the error page error.aspx configured by web.config itself does not exist, so this error makes it confusing to find the real reason. In the final analysis, it is lack of experience.   

after this error is eliminated, the real cause of the error is that 500 errors are reported, which is correct locally; It is also correct to directly enter the server for testing; Open the browser remote call, and an error will be reported. It’s obvious that Google keyword: jQuery reports errors when calling WebService remotely. There are a lot of solutions, which are simple and effective. Here’s a record:

It turns out that the default post setting in web.config does not allow remote calling of WebService. Just change the configuration.    
if you want to call it normally remotely, you need to modify web.config and add the following paragraph under the system.web section

<webServices >
  <protocols >
  <add name="HttpSoap"/>
  <add name="HttpPost"/>
  <add name="HttpGet"/>
  <add name="Documentation"/>
  </protocols>
 </webServices>

Solving the problem of nginx reverse proxy web service soap:address location problem

One: First, let’s publish a web service

package com.ws.service;

public interface IUserService
{
public String getUserName(String id);
}
package com.ws.service;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public class UserService implements IUserService
{
@WebMethod
public String getUserName(@WebParam(name=”id”) String id)
{
return “User:” + id;
}
}
package com.ws.service;

import javax.xml.ws.Endpoint;

public class Server
{
public static void main(String[] args)
{
Endpoint.publish(“http://0.0.0.0:6633/api/v1/user”, new UserService());
System.out.println(“ws startup ok on port ” + 6633);
}
}

The port of ws is 6633
The access address is: http://192.168.100.95:6633/api/v1/user?wsdl

Then, nginx is configured as follows.

upstream webservice {
server 192.168.10.95:6633;
}
server {
listen 6633;
location/{
proxy_pass http://webservice;
}
}

The nginx address is: 192.168.2.123
Then visit the proxy address: http://192.168.2.123:6633/api/v1/user?wsdl

The result is as follows

The address here is clearly wrong.

The solution is as follows

The nginx configuration is changed to

upstream webservice {
server 192.168.100.95:6633;
}
server {
listen 6633;
location/{
proxy_set_header Host $host:$server_port;
proxy_pass http://webservice;
}
}

The reason for this is that if you don’t configure
proxy_set_header Host $host:$server_port;
then, nginx reverse proxy to the backend, passing the Host http header as
Host=webservice