2017-04-06 78 views
1

我創建了一個WCF服務,並且正在使用SOAPUI來發送SOAP請求。明確地在xml根標記中添加名稱空間WCF

下面是請求XML該工具是從我的C#模型生成:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:w3="http://www.w3.org/"> 
    <soapenv:Header /> 
    <soapenv:Body> 
     <w3:PerformScan> 
      <w3:request> 
       <w3:SearchConfiguration> 
        <w3:ConfidenceThreshold>?</w3:ConfidenceThreshold> 
        <w3:ResultConfiguration></w3:ResultConfiguration> 
        <w3:ScanRequest xsi:type="w3:CustomerRequest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
         <w3:CustomerId>?</w3:CustomerId> 
         <w3:CustomerName>?</w3:CustomerName> 
        </w3:ScanRequest> 
       </w3:SearchConfiguration> 
      </w3:request> 
     </w3:PerformScan> 
    </soapenv:Body> 
</soapenv:Envelope> 

但使它能夠發揮我需要修改請求XML。下面是修改並使用XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:w3="http://www.w3.org/"> 
    <soapenv:Header /> 
    <soapenv:Body> 
     <w3:PerformScan xmlns:w3="http://www.w3.org/"> 
      <w3:request> 
       <w3:SearchConfiguration> 
        <w3:ConfidenceThreshold>?</w3:ConfidenceThreshold> 
        <w3:ResultConfiguration></w3:ResultConfiguration> 
        <w3:ScanRequest xsi:type="w3:CustomerRequest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
         <w3:CustomerId>?</w3:CustomerId> 
         <w3:CustomerName>?</w3:CustomerName> 
        </w3:ScanRequest> 
       </w3:SearchConfiguration> 
      </w3:request> 
     </w3:PerformScan> 
    </soapenv:Body> 
</soapenv:Envelope> 

我怎麼能強迫我的C#模型或怎樣做才能使xmlns:w3="http://www.w3.org/"中,同時從工具產生autopopulated PerformScan節點。

+0

兩者都是一樣的,沒有區別。不需要兩次定義相同的名稱空間。 – Rao

+0

是的兩者是相同的。但是我需要在PerformScan或請求節點中添加xmlns:w3 =「http://www.w3.org/」,以使其可行,否則會給出錯誤:屬性'type'具有無效值'w3:CustomerRequest '根據其模式類型'QName' - 'w3'是一個未聲明的前綴。由於我正在使用xsd模式驗證。 –

+0

可能需要在服務器端處理,而不是客戶端。 – Rao

回答

0

瞭解它是您的應用程序的問題。
可能會在腳本下方幫助您,直到您獲得應用程序中的修復程序。

下面是它可以在soapUI的完成:

  • 創建測試用例
  • 添加groovy script測試步驟,第一步說。
  • 添加soap request測試步驟,比如step2。與您目前需要轉換的請求具有相同的請求。

下面的腳本進入步驟1,並根據需要更新步驟2中的請求。

Groovy腳本:這使用固定的xml。

import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep 

def setRequest = { request -> 
    def step = context.testCase.testStepList[context.currentStepIndex+1] 
    if (step instanceof WsdlTestRequestStep) { 
     step.testRequest.requestContent = request 
     log.info "Request for ${step.name} step is updated" 
    } 
} 

def xml = """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:w3="http://www.w3.org/"> 
<soapenv:Header /> 
<soapenv:Body> 
    <w3:PerformScan> 
     <w3:request> 
      <w3:SearchConfiguration> 
       <w3:ConfidenceThreshold>?</w3:ConfidenceThreshold> 
       <w3:ResultConfiguration></w3:ResultConfiguration> 
       <w3:ScanRequest xsi:type="w3:CustomerRequest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
        <w3:CustomerId>?</w3:CustomerId> 
        <w3:CustomerName>?</w3:CustomerName> 
       </w3:ScanRequest> 
      </w3:SearchConfiguration> 
     </w3:request> 
    </w3:PerformScan> 
</soapenv:Body> 
</soapenv:Envelope> 
""" 
setRequest(groovy.xml.XmlUtil.serialize(new XmlSlurper().parseText(xml))) 

如果您想通過動態XML,即工作,讀取第二步請求,並設置更改的XML回來,然後用下面的腳本,而不是上面的一個:

Groovy腳本:

import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep 

def getNextStep = { context.testCase.testStepList[context.currentStepIndex+1] } 

def getRequest = { step ->  
     if (step instanceof WsdlTestRequestStep) { 
      log.info "Getting request for ${step.name}" 
      return step.testRequest.requestContent 
     } 
     null 
} 

def setRequest = { step, request -> 
    if (step instanceof WsdlTestRequestStep) { 
     step.testRequest.requestContent = request 
     log.info "Request for ${step.name} step is updated" 
    } 
} 
def xml = getRequest(getNextStep()) 
if (xml) { 
    setRequest(getNextStep(), groovy.xml.XmlUtil.serialize(new XmlSlurper().parseText(xml)))  
} 

您可以快速地嘗試相同的在線Demo

相關問題