如何将JMeter中的Soap请求发送到WCF服务 - 获取错误请求400错误

时间:2015-11-30 12:51:24

标签: xml web-services wcf soap wsdl

我有以下WCF服务操作:

[ServiceContract(ConfigurationName="IDocumentGenerator")]
    public interface IDocumentGenerator
    {
        [OperationContract(Action = "GenerateDocument")]
        XmlDocument GenerateDocument(int TemplateId, string Format, XmlDocument Payload);
    }

我可以通过导航到服务来在浏览器中加载WSDL。但是,当我在Jmeter中向同一个服务器发送“SOAP / XML-RPC请求”时,我收到响应代码 - 400 - 错误请求。

以下是我正在使用的Soap消息:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
        <GenerateDocument>
            <Format>Pdf</Format>
            <TemplateId>6</TemplateId>
            <Payload><a></a></Payload>
        </GenerateDocument>     
    </soapenv:Body>
</soapenv:Envelope>

1 个答案:

答案 0 :(得分:0)

直接在WCF中不支持XmlDocument作为Operation参数。您需要在OperationContract属性中使用XmlSerializerFormat:

[OperationContract(Action = "GenerateDocument"), XmlSerializerFormat]

我创建的Soap请求也无效。要创建Soap请求,我们可以使用http://www.soapui.org/中的软件。创建有效的Soap请求后,我能够解决问题:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:GenerateDocument>
         <tem:TemplateId>2</tem:TemplateId><tem:Format>2</tem:Format>
         <!--Optional:-->

         <!--Optional:-->
         <tem:Payload>
            <a/>
         </tem:Payload>
      </tem:GenerateDocument>
   </soapenv:Body>
</soapenv:Envelope>
相关问题