2017-04-06 8 views
1

WCFサービスを作成しましたが、SOAPUIを使用してSOAPリクエストを送信しています。xmlルートタグに名前空間を明示的に追加するWCF

<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を変更する必要があり、それが実行可能にする:

は、以下のツールが私のC#モデルから生成された要求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#のモデルやどのようなツールから生成しながらautopopulated xmlns:w3="http://www.w3.org/"PerformScan内のノードを作るために行うに強制することができます。

+0

どちらも同じですが、違いはありません。同じ名前空間を2回定義する必要はありません。 – Rao

+0

はい両方が同一です。しかし、私はPerformScanまたはリクエストノードにxmlns:w3 = "http://www.w3.org/"を追加する必要があります。それ以外の場合はエラーが発生します:属性 'type'に無効な値 'w3:CustomerRequest 'スキーマタイプ' QName 'に従っています - ' w3 'は宣言されていない接頭辞です。私はxsdスキーマ検証を使用しているので。 –

+0

クライアント側よりもサーバー側で対処する必要があるかもしれません。 – Rao

答えて

0

これはアプリケーションに関連する問題です。
このスクリプトでは、アプリケーションで修正プログラムを入手するまでお手伝いします。ここで

は、それがあるsoapUIで行うことができる方法である。

  • groovy scriptテスト工程を追加したテストケース
  • を作成し、STEP1を言います。
  • soap requestテストステップ、たとえばstep2を追加します。あなたが現在変換しようとしているのと同じ要求をしてください。

以下のスクリプトはstep1に進み、必要に応じてstep2の要求を更新します。

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で作業する場合、すなわち、はSTEP2からの要求を読んで、1より上の代わりに、スクリプトの下に使用し、その後、戻って変更された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

を試すことができます
関連する問題