1

Has been using Service Reference without any success:

Web service return only XML

Now I am using the raw SOAP message to do it:

XmlDocument doc = new XmlDocument();
                doc.Load("Service.xml");

                // create the request to your URL
                Uri wsHost = new Uri("http://www.rrr.net/services/Connect");
                HttpWebRequest request = (HttpWebRequest) WebRequest.Create(wsHost);

                // add the headers
                // the SOAPACtion determines what action the web service should use
                request.Headers.Add("SOAPAction", "act");

                // set the request type
                request.ContentType = "text/xml;charset=\"utf-8\"";
                request.Accept = "text/xml";
                request.Method = "POST";

                // add our body to the request
                Stream stream = request.GetRequestStream();
                doc.Save(stream);
                stream.Close();

                // get the response back
                using( HttpWebResponse response = (HttpWebResponse)request.GetResponse() )
                {
                    Stream dataStream = response.GetResponseStream();
                    StreamReader dataReader = new StreamReader(dataStream); 

                    // Use Linq to read the xml response
                    using (XmlReader reader = XmlReader.Create(dataStream))
                    {

The post is correct, but response always give me text/plain empty result, the reponse header:

Headers = {Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/plain
Date: Thu, 06 Sep 2012 15:59:28 GMT

}

The SOAP message is, act is the function:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://webService">
  <soapenv:Header/>
  <soapenv:Body>
    <web:act>
      <web:d1>1</web:d1>
      <web:d2>14</web:d2>
    </web:act>
  </soapenv:Body>
</soapenv:Envelope>

I use SoapUI, below is the raw request from SoapUI, it return a xml result:

POST http://www.rrr.net/services/Connect HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: ""
Content-Length: 516
Host: www.rrr.net
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

Thank you.

Community
  • 1
  • 1
Alvin
  • 8,219
  • 25
  • 96
  • 177

2 Answers2

0

SOAP webservices require action/method to be specified (and NOT empty). If you don't know which action you want you can look at webservice WSDL by invoking the webservice with queryString "?WSDL". I.e. www.yourSite.com/your/Web/Service/URL?WSDL

Germann Arlington
  • 3,315
  • 2
  • 17
  • 19
  • 1
    The the SOAPAction just the function name? – Alvin Sep 06 '12 at 15:47
  • I put in the SOAPAction, still no result. – Alvin Sep 06 '12 at 15:52
  • But, how is the webservice meant to know which one (of possibly many) of it's methods you are trying to call? That is the reason why you have to invoke the webservice with parameters that it will recognise. SOAPAction should contain the actual webservice method you are trying to call. – Germann Arlington Sep 06 '12 at 15:56
  • I added the function no result, the thing is the SoapUI is posting SOAPAction: "", an empty SOAPACTION, still it return a result. – Alvin Sep 06 '12 at 16:00
  • Are you using correct URL? Are you using correct method? Who wrote the webservice? Is your webservice correctly and successfully deployed? Try top access the actual URL of the webservice with "?WSDL" querystring, what do you get? – Germann Arlington Sep 06 '12 at 16:06
  • yes, it is correct, it does return result when I use soapUI to test it out. ?WSDL did return me all the functions. – Alvin Sep 06 '12 at 16:09
  • Pls take a look at question, I have add in The SOAP message. – Alvin Sep 06 '12 at 16:12
  • Is your webservice url a secret? What are the actual URLs that you are posting your requests to? What is the difference between SoapUI headers and the headers you are trying to post? – Germann Arlington Sep 06 '12 at 16:52
0

You must specify an action in both the request and also the service interface. You can set the action value on the interface member using the attributes shown below and then in the request using the method you have used but by specifying the action name you used in the contract:

The attributes on the interface member

[OperationContract Name="YourActionName"]
[WebInvoke (Method = "POST", UriTemplate = "YourActionName")]
Message YourServiceFunction();

One method of specifying the action on the message

Message inputMessage = Message.CreateMessage (MessageVersion.Soap, "YourActionName", reader);
CSharpened
  • 11,674
  • 14
  • 52
  • 86