【问题标题】:WCF Rest service receives null value from SOAPUIWCF Rest 服务从 SOAPUI 接收空值
【发布时间】:2016-05-19 10:01:58
【问题描述】:

我正在尝试在我的开发环境中通过soapui 测试我的wcf 休息服务,虽然我的服务正在被命中,但参数总是收到空值。

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

我的意图是将xml参数发送到内网中的另一个服务。

这是我的服务接口

[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

【问题讨论】:

  • 你在SoapUI发什么帖子?
  • 将其编辑到问题中,然后删除评论。

标签: c# .net wcf rest


【解决方案1】:

希望此解决方案对您有所帮助:

在 Request Properties 面板中,有 Max Size 选项,如果您将其设置为 1048576 (1MB),SoapUI 不会将超过 1MB 的结果加载到内存中。

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

【讨论】:

  • 我尝试设置 MaxSize 属性,但仍然无法正常工作。
【解决方案2】:

很可能问题不在于服务本身,而在于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 命名空间,使其与您在服务上的命名空间相匹配。

【讨论】:

  • 我尝试了您所说的解决方案,但是该解决方案对我不起作用,因为原始 xml 无法通过服务方法“XMLData”。最初我试图将参数作为字符串传递,但为了实现您的解决方案,我创建了一个类并指示了命名空间,但当调试命中代码时,参数中仍然有空值。
猜你喜欢
  • 1970-01-01
  • 2016-06-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-11
相关资源
最近更新 更多