Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF Rest服务从SOAPUI接收空值_C#_.net_Wcf_Rest - Fatal编程技术网

C# WCF Rest服务从SOAPUI接收空值

C# WCF Rest服务从SOAPUI接收空值,c#,.net,wcf,rest,C#,.net,Wcf,Rest,我正试图在我的开发环境中通过soapui测试我的wcf rest服务,尽管我的服务被命中,但参数始终接收空值 我使用POST方法从SOAPUI传递字符串xml,但在XMLData方法的xmlString参数中总是得到null。我在SOAPUI中尝试了各种组合,但每次都收到null值 我的目的是将xml参数发送到intranet中的另一个服务 这是我的服务接口 [ServiceContract] public interface IPayGService { [OperationContr

我正试图在我的开发环境中通过soapui测试我的wcf rest服务,尽管我的服务被命中,但参数始终接收空值

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

我的目的是将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>]]"
公共类付费服务:IPayGService
{
公共void XMLData(字符串xmlString)
{
HttpWebRequest请求=(HttpWebRequest)WebRequest.Create(“http://10.77.146.113:8081/PAGUIManager/rest/response");
字节[]字节;
字节=System.Text.Encoding.ASCII.GetBytes(xmlString);
request.ContentType=“text/xml;encoding='utf-8';
request.ContentLength=字节.Length;
request.Method=“POST”;
Stream requestStream=request.GetRequestStream();
requestStream.Write(字节、0、字节、长度);
requestStream.Close();
HttpWebResponse;
response=(HttpWebResponse)request.GetResponse();
if(response.StatusCode==HttpStatusCode.OK)
{
Stream responseStream=response.GetResponseStream();
字符串responsest=新的StreamReader(responseStream).ReadToEnd();
}
}
}

以下是我试图从SOAP UI“CCCSS1234 PG12345”发布的内容,希望此解决方案能够帮助您:

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

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


最有可能的问题不是服务本身,而是
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>

CCCSS1234 PG123451200成功付款成功888853991123银行123%

我的
SoapUI
比你的版本旧,所以我不知道你应该在哪里测试原始xml。但是我可以在你的屏幕截图中看到
raw
选项卡,所以可能就是这个地方。你可能需要更改
tem
名称空间,使它与你在服务上的名称空间匹配。

你从发布什么ode>SoapUI
?将其编辑到问题中,然后删除注释。我尝试设置MaxSize属性,但它仍然不起作用。我尝试了您所说的解决方案,但是该解决方案对我不起作用,因为原始xml无法通过服务方法“XMLData”“。最初,我试图以字符串形式传递参数,但为了实现您的解决方案,我创建了一个类并指示了名称空间,但在调试命中代码时,参数中仍然得到null值。