locked
Request XML Error - The remote server returned an error RRS feed

  • Question

  • User-1024101449 posted

    I am trying to receive response from my XML through REST API service. I am getting below error.

    i search many ways to find and getting response message but i am not able to get it 

    what is the problem..?

      	    string xml = "&lt;?xml version='1.0' encoding='UTF-8'?><request><header><userName>user1</userId><password>passorduser</password><repositoryName>ABIS</repositoryName></header><body><execute><query>PassQuery<queryString>select emp_no from employee where object_name ='E001'</queryString></query></execute></body></request>";
                
          
                string url = "http://serverdummy.net.company.intranet:80/services/core/QueryService";
                //string url = "http://ww1.caliber.ie/cram/api";
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
    
    
                //string s = "id="+Server.UrlEncode(xml);
                byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(xml);
                req.Method = "POST";
                req.ContentType = "text/xml;charset=utf-8";
                req.ContentLength = requestBytes.Length;
                Stream requestStream = req.GetRequestStream();
                requestStream.Write(requestBytes, 0, requestBytes.Length);
                requestStream.Close();
    
    
                HttpWebResponse res = (HttpWebResponse)req.GetResponse();
                StreamReader sr = new StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);
                string backstr = sr.ReadToEnd();
                TextBox1.Text = backstr;
                sr.Close();
                res.Close();

    Wednesday, May 22, 2019 2:16 PM

Answers

  • User61956409 posted

    Hi gani7787,

    I am trying to receive response from my XML through REST API service. I am getting below error.

    Do you mean that the code causes (400) Bad Request error? As mgebhard mentioned, please try to modify &lt;?xml version='1.0' encoding='UTF-8'?> to 

    <?xml version='1.0' encoding='utf-8'?>

    Besides, your xml string contains <userName>user1</userId> that is not valid, it might be 

    <userName>user1</userName>

    or

    <userId>user1</userId>

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 23, 2019 5:32 AM

All replies

  • User475983607 posted

    I am trying to receive response from my XML through REST API service. I am getting below error.

    i search many ways to find and getting response message but i am not able to get it 

    what is the problem..?

    What is the error?  

    Change this...

     string xml = "&lt;?xml 

    To 

     string xml = "<?xml 

    Have you tried contacting the service owner or reading the docs to make sure your request is properly formatted?

    Wednesday, May 22, 2019 2:46 PM
  • User-1024101449 posted

    I received below error.

    "The remote server returned an error: (500) Internal Server Error."

    I am getting below SOAP XML (Request XML) from my client .

    http://serverdummy.et.company.intranet:80/services/core/QueryService


    Method: POST

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
    <ServiceContext token="temporary/127.0.0.1-1205239338115-25203285"
    xmlns="http://context.core.datamodel.fs.documentum.emc.com/">
    <Identities xsi:type="RepositoryIdentity"
    userName="serverdummy"
    password="password"
    repositoryName="testemp"
    domain=""
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
    <RuntimeProperties/>
    </ServiceContext>
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <execute xmlns="http://core.services.fs.documentum.emc.com/">
    <query xsi:type="q1:PassQuery"
    queryString="select emp_id from employee where object_name ='AO101'"
    xmlns=""
    xmlns:q1="http://query.core.datamodel.fs.documentum.emc.com/">
    <q1:repositories>testemp</q1:repositories>
    </query>
    <execution startingIndex="0"
    maxResultCount="100"
    maxResultPerSource="50"
    cacheStrategyType="DEFAULT_CACHE_STRATEGY"
    xmlns=""/>
    </execute>
    </s:Body>
    </s:Envelope>
    

    When i call the above XML, i just want to get response the message.

    ???

    Thursday, May 23, 2019 5:31 AM
  • User61956409 posted

    Hi gani7787,

    I am trying to receive response from my XML through REST API service. I am getting below error.

    Do you mean that the code causes (400) Bad Request error? As mgebhard mentioned, please try to modify &lt;?xml version='1.0' encoding='UTF-8'?> to 

    <?xml version='1.0' encoding='utf-8'?>

    Besides, your xml string contains <userName>user1</userId> that is not valid, it might be 

    <userName>user1</userName>

    or

    <userId>user1</userId>

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 23, 2019 5:32 AM
  • User-1024101449 posted

    Thanks buddy for your immediate reply.

    i changed the code. but, still same problem.

    Error : The remote server returned an error: (500) Internal Server Error.

    I just want to ensure formatting the code is correct or not.

    .NET CODE

    string xml = "&lt;?xml version='1.0' encoding='UTF-8'?><request><header><userName>user1</userId><password>passorduser</password><repositoryName>ABIS</repositoryName></header><body><execute><query>PassQuery<queryString>select emp_no from employee where object_name ='E001'</queryString></query></execute></body></request>";

    SOAP XML

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Header>
    <ServiceContext token="temporary/127.0.0.1-1205239338115-25203285"
    xmlns="http://context.core.datamodel.fs.documentum.emc.com/">
    <Identities xsi:type="RepositoryIdentity"
    userName="serverdummy"
    password="password"
    repositoryName="testemp"
    domain=""
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
    <RuntimeProperties/>
    </ServiceContext>
    </s:Header>
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <execute xmlns="http://core.services.fs.documentum.emc.com/">
    <query xsi:type="q1:PassQuery"
    queryString="select emp_id from employee where object_name ='AO101'"
    xmlns=""
    xmlns:q1="http://query.core.datamodel.fs.documentum.emc.com/">
    <q1:repositories>testemp</q1:repositories>
    </query>
    <execution startingIndex="0"
    maxResultCount="100"
    maxResultPerSource="50"
    cacheStrategyType="DEFAULT_CACHE_STRATEGY"
    xmlns=""/>
    </execute>
    </s:Body>
    </s:Envelope>

    Anything i missed out in the string xml..

    because, using the same XML, i am getting response from POSTMAN TOOL.

    I am struggling...?

    Thursday, May 23, 2019 6:00 AM
  • User-474980206 posted


    Your .net version of the xml does not have the xml namespaces which are required by soap. Also you used request instead of envelope.
    Thursday, May 23, 2019 2:27 PM
  • User-1024101449 posted

    Yes. My XML like that.

    How do we call envelope XML directly in the code.???

    If this is through, then my problem is solved...

    Friday, May 24, 2019 4:55 AM
  • User-474980206 posted

    your code is correct, your xml is not. You have sample working xml, I don't understand why you can not duplicate it in code. 

    note: there are toolkits that will convert a SOAP wsdl file to code, which is the most common way of using soap. 

    Friday, May 24, 2019 3:17 PM