Passing parameters to webservice method call


#1

Hi everyone, I have an app and want to get some data from a .Net webservice. when I call a method say GetCities() from this wevservice that does not require any parameter using http.get(…), I receive data fine, but in getting data from Select(…) method that require some parameters like {params: {cityCode: 21, Tel: ‘’, FirstName:‘John’, LastName:‘Smith’}} using http.post(‘http://someServer/someApi/apiPage.asmx/Select’, {params …}) , I recieve erro as follows : “Selected web service method is not valid”. Because of this error I wrote an windows application with C# and called both methods and same parameters and it works fine. Then I think my problem is the url or parameter passing in hhtp.post method.
Can everybody please help me and show what is my mistake? Thanks in advanced


#2

Have a look at the network tab of your dev tools and compare the request you are sending with the request your C# app is sending. Often it is easier to use a REST client like Postman to build a working request and then replicate that in the Ionic app.


#3

Thank you Sujan12 for your post. With aid of Postman I got network traffic in two cases and then I corrected a mistake in my request,
and now the error is changed. Before correction I was sent “Select” method name in url but must be send as “op” parameter and now I am sending {params: {op: ‘Select’, cityCode: 21, Tel: ‘’, FirstName:‘John’, LastName:‘Smith’}} using http.get(‘http://someServer/someApi/apiPage.asmx’, {params …}). therefor I receive an OK responese (200).
In xml response instead of data there is a tag as follows:

<html>
  <head>
	  ....
	  <title>
		BCitySupport Web Service
	  </title>
  </head>
  <body>
    <div id="content">
      <p class="heading1">BCitySupport</p><br>
      <span>
          <p class="intro">The following operations are supported.  For a formal definition, please review the Service Description
			<a href="bcitysupport.asmx?WSDL">Service Description</a>. 
		   </p>
            <ul>
              <li>
                <a href="bcitysupport.asmx?op=Delete">Delete</a>
              </li>
              <li>
                <a href="bcitysupport.asmx?op=GetCities">GetCities</a>
              </li>
              <li>
                <a href="bcitysupport.asmx?op=Select">Select</a>
              </li>
            </ul>
		<span>
	</div>
	....
  </body>
 </html>

and in last two days I’ve searched for any similar case that can find the reason but unfortunately had no success.
I were so thankful if you or anyone can help me. thanks in advanced


#4

That is just your backend application telling you that you are not sending the correct request - there still has to be something off.


#5

Thank you Sujan12 for your reply. I’m totally confused, in last week I’ve searched tens of ways to find my mistake in my request to server but had no result. So can I send you webservice wsdl and some javascript code from my application, then you can help me?
Thanks in advanced.


#6

No, I don’t do private support.

I would use Insomnia or Postman to create a working request to your web service and then recreate this request using Ionic/Angular.


#7

Thank you Sujan12 for your quick reply, but I mean that share the infos in this page not privately for you.
I used postman as you said before and I became similar error unfortunately. I select POST method with
url : “http://192.168.254.201/bvoipdatabase/bvoip118support.asmx/Select” and City=-1, Code=-1, Tell=’’, FirstName= ‘john’, LastName= ‘smith’ as parameters
or another request with:
url : “http://192.168.254.201/bvoipdatabase/bvoip118support.asmx” and op= ‘Select’, City=-1, Code=-1, Tell=’’, FirstName= ‘john’, LastName= ‘smith’ as parameters

and in both cases there were errors although every error was different.


#8

Then post away… I have no idea about WSDL, but I’m sure we can figure this out.
Are there maybe libraries or working implementations for that web service? Looking at different stuff that works is a lot easier.


#9

Thank you Sujan12.

The url of webservice method is: "http://192.168.254.201/bapidatabase/bapisupport.asmx"
and wsdl of the webservice is:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <wsdl:types>
    <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
      <s:element name="GetCities">
        <s:complexType />
      </s:element>
      <s:complexType name="ArrayOfM_Cities">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="unbounded" name="m_Cities" nillable="true" type="tns:m_Cities" />
        </s:sequence>
      </s:complexType>
      <s:complexType name="m_Cities">
        <s:sequence>
          <s:element minOccurs="1" maxOccurs="1" name="City_Code" type="s:int" />
          <s:element minOccurs="0" maxOccurs="1" name="City_Name" type="s:string" />
        </s:sequence>
      </s:complexType>
      <s:element name="Select">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="City" nillable="true" type="s:int" />
            <s:element minOccurs="1" maxOccurs="1" name="Code" nillable="true" type="s:int" />
            <s:element minOccurs="0" maxOccurs="1" name="Tell" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="FirstName" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="LastName" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:element name="Delete">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="1" maxOccurs="1" name="City" nillable="true" type="s:int" />
            <s:element minOccurs="1" maxOccurs="1" name="Code" nillable="true" type="s:int" />
            <s:element minOccurs="0" maxOccurs="1" name="Tell" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="FirstName" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="LastName" type="s:string" />
          </s:sequence>
        </s:complexType>
      </s:element>
    </s:schema>
  </wsdl:types>
  </wsdl:message>
  <wsdl:message name="GetCitiesSoapIn">
    <wsdl:part name="parameters" element="tns:GetCities" />
  </wsdl:message>
  <wsdl:message name="GetCitiesSoapOut">
    <wsdl:part name="parameters" element="tns:GetCitiesResponse" />
  </wsdl:message>
  <wsdl:message name="SelectSoapIn">
    <wsdl:part name="parameters" element="tns:Select" />
  </wsdl:message>
  <wsdl:message name="SelectSoapOut">
    <wsdl:part name="parameters" element="tns:SelectResponse" />
  </wsdl:message>
  <wsdl:message name="DeleteSoapIn">
    <wsdl:part name="parameters" element="tns:Delete" />
  </wsdl:message>
  <wsdl:message name="DeleteSoapOut">
    <wsdl:part name="parameters" element="tns:DeleteResponse" />
  </wsdl:message>
  <wsdl:message name="GetCitiesHttpGetIn" />
  <wsdl:message name="GetCitiesHttpGetOut">
    <wsdl:part name="Body" element="tns:ArrayOfM_Cities" />
  </wsdl:message>
  <wsdl:message name="GetCitiesHttpPostIn" />
  <wsdl:message name="GetCitiesHttpPostOut">
    <wsdl:part name="Body" element="tns:ArrayOfM_Cities" />
  </wsdl:message>
  <wsdl:portType name="BApiSupportSoap">
    <wsdl:operation name="GetCities">
      <wsdl:input message="tns:GetCitiesSoapIn" />
      <wsdl:output message="tns:GetCitiesSoapOut" />
    </wsdl:operation>
    <wsdl:operation name="Select">
      <wsdl:input message="tns:SelectSoapIn" />
      <wsdl:output message="tns:SelectSoapOut" />
    </wsdl:operation>
    <wsdl:operation name="Delete">
      <wsdl:input message="tns:DeleteSoapIn" />
      <wsdl:output message="tns:DeleteSoapOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:portType name="BApiSupportHttpGet">
    <wsdl:operation name="GetCities">
      <wsdl:input message="tns:GetCitiesHttpGetIn" />
      <wsdl:output message="tns:GetCitiesHttpGetOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:portType name="BApiSupportHttpPost">
    <wsdl:operation name="GetCities">
      <wsdl:input message="tns:GetCitiesHttpPostIn" />
      <wsdl:output message="tns:GetCitiesHttpPostOut" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="BApiSupportSoap" type="tns:BApiSupportSoap">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="GetCities">
      <soap:operation soapAction="http://tempuri.org/GetCities" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="Select">
      <soap:operation soapAction="http://tempuri.org/Select" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="Delete">
      <soap:operation soapAction="http://tempuri.org/Delete" style="document" />
      <wsdl:input>
        <soap:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="BApiSupportSoap12" type="tns:BApiSupportSoap">
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="GetCities">
      <soap12:operation soapAction="http://tempuri.org/GetCities" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="Select">
      <soap12:operation soapAction="http://tempuri.org/Select" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="Delete">
      <soap12:operation soapAction="http://tempuri.org/Delete" style="document" />
      <wsdl:input>
        <soap12:body use="literal" />
      </wsdl:input>
      <wsdl:output>
        <soap12:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="BApiSupportHttpGet" type="tns:BApiSupportHttpGet">
    <http:binding verb="GET" />
    <wsdl:operation name="GetCities">
      <http:operation location="/GetCities" />
      <wsdl:input>
        <http:urlEncoded />
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:binding name="BApiSupportHttpPost" type="tns:BApiSupportHttpPost">
    <http:binding verb="POST" />
    <wsdl:operation name="GetCities">
      <http:operation location="/GetCities" />
      <wsdl:input>
        <mime:content type="application/x-www-form-urlencoded" />
      </wsdl:input>
      <wsdl:output>
        <mime:mimeXml part="Body" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="BApiSupport">
    <wsdl:port name="BApiSupportSoap" binding="tns:BApiSupportSoap">
      <soap:address location="http://192.168.254.201/bapidatabase/bapiSupport.asmx" />
    </wsdl:port>
    <wsdl:port name="BApiSupportSoap12" binding="tns:BApiSupportSoap12">
      <soap12:address location="http://192.168.254.201/bapidatabase/bapiSupport.asmx" />
    </wsdl:port>
    <wsdl:port name="BApiSupportHttpGet" binding="tns:BApiSupportHttpGet">
      <http:address location="http://192.168.254.201/bapidatabase/bapiSupport.asmx" />
    </wsdl:port>
    <wsdl:port name="BApiSupportHttpPost" binding="tns:BApiSupportHttpPost">
      <http:address location="http://192.168.254.201/bapidatabase/bapiSupport.asmx" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

and in my controller in ionic app I use following code snippet:


    var config = {
        headers : {
            'Content-Type': 'application/json'
        }
    }   

    var dataParam = {
        City:-1, 
        Code:-1,
        Tell:'',
        FirstName:'john', 
        LastName:'smith'
    }

    $http.post(ApiProvinceEndPoint.url + '/bapisupport.asmx/Select', dataParam, config)
      .then(function(response) {
        console.log('Api.getApiData: ', response);

        var jsonObj = x2js.xml_str2json(response.data);

        console.log('JsonObject: ' + JSON.stringify(jsonObj));

        ....
});

and then I got the error at the call to $http.post: “Select Web Service method name is not valid”

In addition for test I wrote an .net application to access all methods in webservice on the same machine and it works fine. Then I think that my problem is in usage of angularjs in url or parameters in $http.post.

Now I think (from wsdl) that for this method (‘Select’), I can not use $http.post, but also I must be sent a HttpSoap request. Is this true?


#10

Then just use a proxy like Charles Web Proxy to see which request is fired by your .NET app. You can then compare that with the request your Ionic app is sending.


#11

Although in .Net windows application, .Net send a POST request (I know that from a sniff on network traffic via Ethereal)


#12

I try to post network traffic details for these two requests as soon as possible.
I could not attach these whole files.


#13

Hi Sujan12, first two image are network traffic for request in ionic:

and next three image shows request in .Net framework:


#14

You should really try Charles Web Proxy, with this you will be able to simply copy/paste the whole request. If you also activate the proxy for your Ionic app, you can also just diff the two requests in e.g. Winmerge and compare them.