1

一直使用Service Reference没有成功:

Web 服务仅返回 XML

现在我正在使用原始 SOAP 消息来执行此操作:

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))
                    {

帖子是正确的,但response总是给我text/plain空的结果,响应头:

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

}

SOAP 消息是,act 是函数:

<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>

我使用SoapUI,下面是来自 SoapUI 的原始请求,它返回一个 xml 结果:

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)

谢谢你。

4

2 回答 2

0

您必须在请求和服务接口中都指定一个操作。您可以使用下面显示的属性在接口成员上设置操作值,然后使用您使用的方法在请求中设置操作值,但通过指定您在合同中使用的操作名称:

接口成员的属性

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

一种指定消息操作的方法

Message inputMessage = Message.CreateMessage (MessageVersion.Soap, "YourActionName", reader);
于 2012-09-06T15:52:48.903 回答
0

SOAP Web 服务需要指定动作/方法(并且不是空的)。如果您不知道要执行哪个操作,可以通过使用 queryString "?WSDL" 调用 Web 服务来查看 Web 服务 WSDL。IEwww.yourSite.com/your/Web/Service/URL?WSDL

于 2012-09-06T15:40:17.023 回答