Using a web service dynamically using HttpWebRequest without a service reference

The application that I work with will have to send data to an external system. The system system will have a web service (C # or java or php), and I need to use it. Since there will be as many external systems as there are clients, I need to get the WSDL file, the method name and parameters as user input and send the data to the external system.

So, I am trying to call a web service dynamically using the available code here

I checked some free web services here

I find the SOAP location, method name and parameters from the WSDL file and give the same thing as the input.

The following service works as expected

http://soaptest.parasoft.com/calculator.wsdl Location - http://ws1.parasoft.com/glue/calculator Method Name - add Parameter - x,y 

But when I tried the same for another free service, specifying the SOAP location and method name, it gives 500 Internal server error.

 http://www.predic8.com:8080/crm/CustomerService?wsdl Location - http://www.predic8.com:8080/crm/CustomerService Method Name - getAll 

I confirmed that these inputs are correct by testing the above wsdl in soapUI. The same location is used in the soapUI request window.

I am not sure why this generates an error. Please help me figure this out.

Also, please let me know, I get a service location of the WSDL file and use HttpWebRequest to get an answer. I am afraid that this method of calling a web service will work regardless of the technology used to implement the web service.

EDIT:

The problem is with the SOAP envelope.

For http://soaptest.parasoft.com/calculator.wsdl , even if we ignore xmlns: cal = "http://www.parasoft.com/wsdl/calculator/, it succeeds.

But for http://www.predic8.com:8080/crm/CustomerService?wsdl , if I ignore xmlns: ns = "http://predic8.com/wsdl/crm/CRMService/1/, it calls the internal server error.

Tell me how I can be shared here.

+3
source share
1 answer

The problem is that you are using request data. The request does not pass validation, as does the error.

If you import the provided wsdl and confirm the creation request, it will be clear what the problem is.

Person and Customer have an id element, and the data must follow a specific pattern, which is defined in the ../common/1

Here is a link to a schema that has a simpleType constraint :

  <xsd:simpleType name="IdentifierType"> <xsd:annotation> <xsd:documentation>Identifier for business objects.</xsd:documentation> </xsd:annotation> <xsd:restriction base="xsd:string"> <xsd:pattern value="[AZ]{2}-\d{5}"/> </xsd:restriction> </xsd:simpleType> 

So, the id value should have the value AA-12345 , i.e. two uppercase letters, a hyphen (-) and the next 5 digits.

Modify your request according to the above template and you should be good.

Hope this will be helpful.

0
source

Source: https://habr.com/ru/post/909552/


All Articles