WCF Rest服务从SOAPUI接收空值

时间:2016-05-19 10:01:58

标签: c# .net wcf rest

我试图在我的开发环境中通过soapui测试我的wcf rest serice,虽然我的服务被命中但参数总是接收空值。

我使用POST方法从SOAPUI传递字符串xml,但我总是在XMLData方法的xmlString参数中得到null。我尝试了SOAPUI中的各种组合,但每次收到空值。

我的目的是将xml参数发送到Intranet中的另一个服务。

这是我的服务界面

[ServiceContract]
public interface IPayGService
{
    [OperationContract]
       [WebInvoke(Method="POST",RequestFormat=WebMessageFormat.Xml,ResponseFormat=WebMessageFormat.Xml,BodyStyle=WebMessageBodyStyle.Bare,UriTemplate="XMLData")]
    void XMLData(string xmlString);
}

以下是上述服务合同的实施

public class PayGService : IPayGService
{
    public void XMLData(string xmlString)
    {
        HttpWebRequest request =     (HttpWebRequest)WebRequest.Create("http://10.77.146.113:8081/PAGUIManager/rest/response");
        byte[] bytes;
        bytes = System.Text.Encoding.ASCII.GetBytes(xmlString);
        request.ContentType = "text/xml; encoding='utf-8'";
        request.ContentLength = bytes.Length;
        request.Method = "POST";
        Stream requestStream = request.GetRequestStream();
        requestStream.Write(bytes, 0, bytes.Length);
        requestStream.Close();
        HttpWebResponse response;
        response = (HttpWebResponse)request.GetResponse();
        if (response.StatusCode == HttpStatusCode.OK)
        {
            Stream responseStream = response.GetResponseStream();
            string responseStr = new     StreamReader(responseStream).ReadToEnd();
        }
    }
}


Here's what I'm trying to post from SOAP UI "<![CDATA[<response>    <requestType>CC</requestType><pagTransId>CSS1234</pagTransId>    <pgTransId>PG12345</pgTransId><amount>1200</amount><Status>SUCCESS</Status>        <message>Payment Successful</message><MSISDIN>8888853991</MSISDIN><bankRef>123bank</bankRef>    <bankCode>123</bankCode><checkSum>%%%%%%%^^^^&&& </checkSum>    <cartInfo>8888853991:001:100</cartInfo></response>]]"

Here's the SOAPUI Snapshot

2 个答案:

答案 0 :(得分:0)

希望此解决方案能为您提供帮助:

  

在“请求属性”面板中,有选项“最大大小”,如果将其设置为,例如1048576(1MB),SoapUI不会将超过1MB的结果加载到内存中。

     

如果在同一面板中使用Dump File属性,则可以轻松地将完整响应转储到文件中,从而避免使用内存。

答案 1 :(得分:0)

问题很可能不在于服务本身,而在于SoapUI正在发送的内容。

我使用与您的问题相同的OperationContract进行了小型测试服务。然后我在SoapUI中创建一个项目来测试它。从SoapUI发送时,此原始xml有效:

<soapenv:Envelope 
   xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
   xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:XMLData>
         <tem:xmlString><![CDATA[<response>    <requestType>CC</requestType><pagTransId>CSS1234</pagTransId>    <pgTransId>PG12345</pgTransId><amount>1200</amount><Status>SUCCESS</Status>        <message>Payment Successful</message><MSISDIN>8888853991</MSISDIN><bankRef>123bank</bankRef>    <bankCode>123</bankCode><checkSum>%%%%%%%^^^^&&& </checkSum>    <cartInfo>8888853991:001:100</cartInfo></response>]]></tem:xmlString>
      </tem:XMLData>
   </soapenv:Body>
</soapenv:Envelope>

我的SoapUI版本比您的版本旧,所以我不知道您应该在哪里测试原始xml。但是我可以在屏幕截图中看到Raw标签,所以也许就是这个地方。您可能必须更改tem命名空间,以使其与您在服务上的命名空间匹配。

相关问题