This article is a mirror article of machine translation, please click here to jump to the original article.

View: 26959|Reply: 0

[Source] Java calls to the C# webservice server fail to recognize the value of the HTTP header SOAPAction

[Copy link]
Posted on 2021-3-4 13:19:39 | | | |
Why does the webservice reporting server that calls C# fail to recognize the value of the http header SOAPAction and always let C# change it, just because C# only needs to add a tag, why can't JAVA specify an action request?



Publishing and calling Webservice is very simple, but there are still minor problems, which are summarized as follows:

Java calls .net's webService with a "Server failed to recognize the value of HTTP header SOAPAction" error.

Solution:

When calling webservice, no SoapAction is specified, no RequestNameSpace is specified, so "The server failed to recognize the value of the HTTP header SOAPAction" always appears when requesting.

If using Axis calls, call them as follows:


public static void main(String[] args) throws  Exception {  
    Not bringing? wsdl suffix
    String endpoint = "http://webservice.webxml.com.cn/webservices/qqOnlineWebService.asmx";
  Create a service call     
  Service service = new Service();
  Create a call object through service
  Call call = (Call) service.createCall();   
  Set the URL where the service is located   
  call.setTargetEndpointAddress(new java.net.URL(endpoint));   
  qqCheckOnline is the method "http://WebXml.com.cn/" on the net side, which also pays attention to the address of the Namespace, and will also report an error if you don't bring it
  call.setOperationName(new QName("http://WebXml.com.cn/","qqCheckOnline"));
  qqCode is also the parameter name of the .NET method, which is the parameter name of qqCheckOnline
  call.addParameter(new QName("http://WebXml.com.cn/","qqCode"),
         org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
  Avoid Java calling .net's webService with the error "The server failed to recognize the value of the HTTP header SOAPAction"
  call.setUseSOAPAction(true);
  call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_STRING); The type of parameter returned
  call.setSOAPActionURI("http://WebXml.com.cn/qqCheckOnline"); This should also be noted that you need to add the method to be called, otherwise an error will also be reported
  Object arrays encapsulate the parameters     
  String ret = (String) call.invoke(new Object[] {"aaaaa"});   
  System.out.println("--------"+ret);
    }

Note the comments section.

The hyperlink login is visible.? WSDL stands for Public Web Service

The following exception occurs when the wsdl2java.bat using CXF generates a client to publish a .net webservice based on a wsdl file


( undefined element declaration 's:schema')

Solution:

Open the wsdl.xml and use


<s:any minOccurs="2" maxOccurs="2"/>Alternate <s:element ref="s:schema" /><s:any />
This wsdl2java generation error should be related to JAXB not supporting xml refs, because <s:any minOccurs="2" maxOccurs="2"/> and <s:element ref="s:schema" /><s:any/> are actually equivalent. <s:element ref="s:schema" /> actually means that you can use any element type specified by s:schema here, <s:any /> plays this role, <s:any minOccurs="2" maxOccurs="2"/> is just two <s:any />

It was just written in one sentence.

referenceThe hyperlink login is visible.

Using CXF's wsdl2java.bat generates a client compilation super error based on the wsdl file

Solution:

It does not compile properly because the jax-ws2.2 specification conflicts with java6.

However, the program cannot be compiled only in java5, so it is necessary to lower the jax-ws specification version, which can be handled like this: Execute the command

wsdl2java -frontend jaxws21 -client *.xml

In this way, the code generated with jax-ws2.1 can be compiled and executed in java6.

I compared the client code generated by the tool with text comparison and found that the latter generated 3 more client code, so removing the 3 constructors that reported errors can also solve the above problems.

Reprinted from:The hyperlink login is visible.




Previous:.NET/C# uses BenchmarkDotNet to test code performance
Next:Consul HTTP API interface call
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com